Difficulty: Easy
Correct Answer: str1=India str2=CURIOUSTAB
Explanation:
Introduction / Context:
This macro uses the C preprocessor’s stringification operator #
to print both the parameter names and their string values. Understanding #
helps in building debugging and logging helpers that display variable names with their contents.
Given Data / Assumptions:
#define JOIN(s1, s2) printf("%s=%s %s=%s\n", #s1, s1, #s2, s2)
str1 = "India"
, str2 = "CURIOUSTAB"
Concept / Approach:
The stringification operator #
converts the macro argument token sequence into a string literal. Hence #s1
becomes "str1"
and #s2
becomes "str2"
. The other arguments (without #
) pass the variable values, which are pointers to the respective strings. The final output is the variable names and their stored strings.
Step-by-Step Solution:
#s1
→ "str1", s1
→ "India".#s2
→ "str2", s2
→ "CURIOUSTAB".Printed line: str1=India str2=CURIOUSTAB
.
Verification / Alternative check:
Change str1
to another variable name (e.g., country
) and observe that the left-hand label changes accordingly.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming #
stringifies the value instead of the token; swapping names and values.
Final Answer:
str1=India str2=CURIOUSTAB.
Discussion & Comments