4 Answers
4

amessage is of type char[16]. It is an array. The elements of the array contain the sixteen characters from the string literal.

pmessage is of type char*. It is a pointer. It points to a (non-modifiable) array containing the sixteen characters from the string literal. (You should avoid using a char* to point to a string literal; doing so is evil. You should always use a const char* wherever possible when referring to string literals.)

To clarify the second, the string literal itself is immutable, but the type of pmessage lies and says its mutable, do to a (terrible) special-case conversion.
–
GManNickGFeb 11 '11 at 6:54

@GMan: It's technically not special-cased in C, since the literal is of type char[N] not const char[N] like in C++. I agree that it is evil to use a char* to refer to a string literal though.
–
James McNellisFeb 11 '11 at 6:57

In addition to James McNellis's answer, amessage is one thing -- an array of 16 characters on the stack that happens to contain the string "now is the time" (because they are copied there when amessage is created). You can change what it contains.

On the other hand, pmessage is two things -- a string literal (which is stored in a non-writable portion of memory), and a pointer. You can't change the contents of the string literal, but you can change what the pointer points to, and make it point at a different string. And you can use the string literal as a target of other pointers.

(In some sense, this is not entirely true -- amessage also involves a string literal, as it's where the contents are copied from when it's created. But you can't do anything else with that string literal afterwards.)

amessage is indeed a non-modifiable lvalue because it is an array. This means, effectively, that the named amessage is not assignable; it does not mean that the elements of the array are not assignable (they are assignable). pmessage is indeed a modifiable lvalue (it's a pointer). This means that you can change the pointer to point at a different object. Declaring it as a const char* does not make it a non-modifiable lvalue: it would make it a modifiable lvalue that points to a const char.
–
James McNellisFeb 11 '11 at 16:14

Yes. Amended example. Just trying to help ... :-)
–
David VictorFeb 13 '11 at 9:23