1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

int main(int argc, char* argv[]) {
    const char* str = "Hello World";
    str[0] = 'a';
/*
read_only_string.c: In function 'main':
read_only_string.c:8:16: error: assignment of read-only location '*str'
    8 |         str[0] = 'a';
      |                ^
*/

    const char str_on_stack[] = "Hello World";
    //str_on_stack[0] = 'a';
/*
read_only_string.c: In function 'main':
read_only_string.c:10:25: error: assignment of read-only location 'str_on_stack[0]'
   10 |         str_on_stack[0] = 'a';
      |                         ^
     */



    // this is just printing in a for loop using fputc  
    fputs(str, stdout);
    fputs(str_on_stack, stdout);
    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2024 Alexander J. Quinn & David Burnett         This content is protected and may not be shared, uploaded, or distributed.