Ok, I know that this is invalid
char char_A = 'A';
const char * myPtr = &char_A;
*myPtr = 'J'; // error - can't change value of *myP
[Because we declared a pointer to a constant character]
Why is this valid?
const char *linuxDistro[6]={ "Debian", "Ubuntu", "OpenSuse", "Fedora", "Linux Mint", "Mandriva"};
for ( int i=0; i < 6; i++)
cout << *(linuxDistro+i)<< endl;
*linuxDistro="WhyCanIchangeThis";// should result in an error but doesnt ?
for ( int i=0; i < 6; i++)
cout << *(linuxDistro+i)<< endl;
Thanks for looking!
You write
which is perfectly valid, because the declaration of
linuxDistrowasi. e. it’s an array of 6 pointers to
const char. That is, you can change the pointers themselves, just not the characters pointed to by those pointers. I. e., you can not compileto obtain the string
"Bebian", becuse the strings contain constant characters…What you probably want is an array of constant pointers to constant characters: