In the declaration const char *p, what exactly is const?
Correct answer
C. The pointed-to characters cannot be modified
15 views
C. The pointed-to characters cannot be modified
15 views
Reading the declaration right to left gives pointer to const char, so the pointee is read-only while p itself may be pointed elsewhere. char * const p is the mirror image: the pointer is fixed but the characters may change, and const char * const p freezes both. This distinction matters when passing string literals, which must never be written through a plain char *.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.