Difficulty: Easy
Correct Answer: Yes, it will print endlessly
Explanation:
Introduction / Context:
This program uses a macro to represent an infinite loop and asks whether the subsequent printf
is executed repeatedly. Understanding macro expansion and loop syntax is required.
Given Data / Assumptions:
#define INFINITELOOP while(1)
main
, the macro appears directly before printf
.
Concept / Approach:
After preprocessing, the code becomes while(1)printf("CuriousTab"); which is a standard while loop whose body is the single statement printf("CuriousTab");
. Since the condition is always true, the body executes forever, repeatedly printing the message.
Step-by-Step Solution:
Expand macro: INFINITELOOP
→ while(1)
.Interpretation: loop body is the next statement, i.e., printf
.Because the condition is true, the loop never terminates; printing occurs continuously.
Verification / Alternative check:
Add braces to limit scope: INFINITELOOP { break; }
or rewrite as for(;;)
to observe similar infinite behavior. Inserting a break
or changing the condition to while(0)
alters the outcome.
Why Other Options Are Wrong:
Prints once — contradicted by the loop. No output — false because the loop body calls printf
. Does not compile — the construct is valid; a semicolon is not required after while(1)
when a statement follows.
Common Pitfalls:
Forgetting braces in loops leading to only the next statement being controlled; assuming macros need semicolons; not flushing output or buffering effects (output may be buffered, but it still loops).
Final Answer:
Yes, it will print endlessly
Discussion & Comments