1. Home
  2. Computer Science MCQs
  3. C Programming
  4. const char s[] = "abcdef"; is written as two adjacent…

Added 30 Nov -0001

const char s[] = "abcdef"; is written as two adjacent literals, "abc" and "def". How many characters does the array hold, including the terminator?

  1. 6, because the literals share one terminator between them
  2. 9, because a separator character is inserted between the two literals
  3. 7, because adjacent literals are concatenated before compilation Correct answer
  4. 8, because each literal keeps its own terminating null character

Correct answer

C. 7, because adjacent literals are concatenated before compilation

23 views

MCQSEXAM

Explanation

Adjacent string literals are concatenated in translation phase 6, after preprocessing and before compilation proper, so the result is one literal abcdef with a single terminating NUL and the array has 7 characters. This is how long messages are split across source lines without a + operator, which would be invalid for arrays. Each literal is a separate token during preprocessing, so macros that stringise arguments cannot rely on the split.

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