Comment on the following?
const int *ptr;
Answer: A
Correct answer: You cannot change the value pointed by ptr
The const applies to what ptr points at, not to ptr itself, so *ptr = 5 is rejected while ptr = &other is allowed.
Read such declarations from the identifier outwards, or apply the rule that const qualifies whatever lies to its left unless there is nothing there, in which case it qualifies what lies to its right. int * const ptr reverses the meaning - a constant pointer to a modifiable int - and const int * const ptr fixes both.
Please log in or register to report this question.