const char s[] = "abcdef"; is written as two adjacent literals, "abc" and "def". How many characters does the array hold, including the terminator?
Correct answer
C. 7, because adjacent literals are concatenated before compilation
23 views
C. 7, because adjacent literals are concatenated before compilation
23 views
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.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.