1. Home
  2. Computer Science MCQs
  3. C Programming
  4. In the declaration const char *p, what exactly is const?

Added 30 Nov -0001

In the declaration const char *p, what exactly is const?

  1. Both the pointer and the characters are fixed
  2. Nothing, since const is ignored on pointers
  3. The pointed-to characters cannot be modified Correct answer
  4. The pointer p cannot be reassigned

Correct answer

C. The pointed-to characters cannot be modified

15 views

MCQSEXAM

Explanation

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 *.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? 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