1. Home
  2. Computer Science MCQs
  3. C Programming
  4. Which declaration makes the pointed-to int read-only while…

Added 30 Nov -0001

Which declaration makes the pointed-to int read-only while still allowing the pointer itself to be reassigned?

  1. volatile int * const p
  2. const int *p Correct answer
  3. int * const p
  4. const int * const p

Correct answer

B. const int *p

16 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs