C language: Will this program compile successfully and what does the concatenation of adjacent string literals do? #include<stdio.h> int main() { printf("India" "CURIOUSTAB "); return 0; }

Difficulty: Easy

Correct Answer: Yes

Explanation:

Introduction / Context:This question tests knowledge of a core C feature: adjacent string literals are concatenated by the compiler at translation time. It also checks whether such code compiles without special flags.

Given Data / Assumptions:

  • The program uses two adjacent string literals: "India" "CURIOUSTAB".
  • Standard-compliant C compiler is assumed.

Concept / Approach:In C, two or more string literals separated by whitespace are concatenated into a single string literal before code generation. Thus "India" "CURIOUSTAB" becomes "IndiaCURIOUSTAB". This is used widely for long format strings or macros.

Step-by-Step Solution:The compiler concatenates the literals → one string: "IndiaCURIOUSTAB".printf prints it followed by a newline.The program compiles and runs correctly.

Verification / Alternative check:Replace with printf("India""CURIOUSTAB"); and observe identical behavior; check the generated object with strings utility to see the combined literal.

Why Other Options Are Wrong:“No” contradicts the standard; optimization level is irrelevant. It works in both C and C++. There is no “garbage” because the final literal is well-defined.

Common Pitfalls:Forgetting the newline; assuming run-time concatenation is required instead of the compile-time rule.

Final Answer:Yes

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion