In the first code fragment, message
is a pointer to a read-only array of characters. You can modify the pointer (e.g. ++message
is fine), but you cannot modify what it points to (message[0] = 'X'
invokes undefined behavior).
In the second code fragment, message
is an array of characters with an initializer. You cannot modify the variable (++message
is invalid), but you can modify the contents of the array (message[0] = 'X'
is fine).
Also sizeof(message)
is likely to be different.
They behave similarly when you simply access message[0]
; that is, either you are wrong about your claimed behavior or your compiler has a very surprising bug.
But they are different things and behave differently in several ways, some of which I just enumerated.