Originally Posted by
tabstop
What you mean like a[1][2]='b'?
Yes, this is what I was after. The compiler complains when const is used, and if it's not used then the program gets compiled but then crashes. This is what I wanted to see.
Thank you Sebastiani for this notation. My book mentions that read-only sections of the memory but doesn't (clearly) show an alternative.
So the options are:
Code:
const char *c[2] = { "alpha", "beta" };
const char d[][6] = { { "alpha" }, { "beta" } };
The first one should be used only when no modifications will be performed on the strings ever, regardless whether the const quantifier is used or not, and the second one can be modified when there is no const but it wastes memory when strings are of different lengths. Is this correct?
Why some compilers store elements of string arrays in read-only sections of memory when no const is used? Is there any particular reason behind it?