1. Home
  2. Computer Science MCQs
  3. C Programming
  4. A char pointer is set to point at a string literal. What…

Added 30 Nov -0001

A char pointer is set to point at a string literal. What happens if the program writes through that pointer?

  1. A compile-time error is reported
  2. The literal is copied before writing
  3. The write is silently discarded
  4. The behaviour is undefined Correct answer

Correct answer

D. The behaviour is undefined

14 views

MCQSEXAM

Explanation

String literals are not modifiable objects, so writing through a pointer to one is undefined behaviour.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

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