Which declaration makes the pointed-to int read-only while still allowing the pointer itself to be reassigned?
Correct answer
B. const int *p
16 views
B. const int *p
16 views
Const placement is read right to left: const int *p makes the pointee const, while int * const p makes the pointer itself const. The two-const form, const int * const p, freezes both so the pointer cannot be reseated either. Const binds to the token immediately on its left, or to the type on its right when nothing is there.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is B? Ask here and get an explanation.