20 Feb
2013
20 Feb
'13
7:25 p.m.
On Wed, Feb 20, 2013 at 05:38:38PM +0000, Phil Mayers wrote:
I freely admit to finding const in C confusing.
The most frequently seen example which helps me remember this: const char *p; // equivalently: char const *p; Read right-to-left: "p is a pointer to constant char". You can change p (e.g. p++ is OK) but you cannot change the char which p points to (*p = '\0' is verboten) The less common one is char *const p; "p is a constant pointer to char". That is, p itself is a constant and cannot change, but the thing pointed to by p can be changed.