A char pointer is set to point at a string literal. What happens if the program writes through that pointer?
-
A
A compile-time error is reported
-
B
The literal is copied before writing
-
C
The write is silently discarded
-
D
The behaviour is undefined
Correct answer
Correct answer
D. The behaviour is undefined
14 views
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
Doubts & discussion
Not sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ