G
Guest
From the book
"There is an important difference between these definitions:
char amessage[]="now is the time";
char *pmessage ="now is the time";
snip
On the other hand, pmessage is a pointer, initialized to point a
string const; the pointer may be modified to point elsewhere, but the
result is undefined if you try to modify the string constants."
1) So the statement
*pmessage='b';
may not change 'now' to 'bow'??????
but the statement
amessage[0]='b';
is always guaranteed to change 'now' to 'bow'
Please note there is no mention of the const qualifier in the text. I
understand amessage is a constant pointer to a char, but really don't
understand why pmessage is pointer to a constant char, especially if I
decide to use pmessage as an auto variable (implying that the stack in
RAM (read/write storage) will hold "now is the time"
"There is an important difference between these definitions:
char amessage[]="now is the time";
char *pmessage ="now is the time";
snip
On the other hand, pmessage is a pointer, initialized to point a
string const; the pointer may be modified to point elsewhere, but the
result is undefined if you try to modify the string constants."
1) So the statement
*pmessage='b';
may not change 'now' to 'bow'??????
but the statement
amessage[0]='b';
is always guaranteed to change 'now' to 'bow'
Please note there is no mention of the const qualifier in the text. I
understand amessage is a constant pointer to a char, but really don't
understand why pmessage is pointer to a constant char, especially if I
decide to use pmessage as an auto variable (implying that the stack in
RAM (read/write storage) will hold "now is the time"