So if I do:
char * a = "hello";
“hello” is stored in the RODATA section and a points to it. If I do:
char a[10] = "hello";
“hello” is stored on the STACK in an array of 10 bytes called a.
What happens when I do:
char * a[10] = {"hello", "hi"}
So, we have an array of 10 character pointers which will be stored on the STACK. But what about the string literals? Do they go in the RODATA section?
Also, does the same thing happen with argv?
The elements of the array are pointers to string literals. As any string literal they are also non-modifiable and the implementation can store them in read-only memory.
Now for your second question:
No, because they are not string literals. The pointers in
argvand the strings pointed to can be modified. This is guaranteed by the C Standard.