Difficulty: Easy
Correct Answer: No output
Explanation:
Introduction / Context:
This question targets integer width assumptions and initialization effects. Assigning a value outside the range of a 16-bit unsigned type causes wraparound, which directly determines whether the loop body executes at all.
Given Data / Assumptions:
unsigned int is assumed to be 16 bits (0..65535).65536 is exactly 2^16, so it wraps to 0 on assignment in a 16-bit unsigned int.while loop executes only if i != 0.
Concept / Approach:
On a 16-bit model, unsigned int i = 65536; stores 0 because 65536 mod 65536 = 0. Therefore the loop condition (i != 0) is false at the first test, and the loop body is skipped entirely. Only the trailing newline is printed, which most judges interpret as “no visible output.”
Step-by-Step Solution:
i != 0 → false → loop not entered.Program prints only "\n".
Verification / Alternative check:
Change the initializer to 65535 and observe the loop execute; or print the value of i immediately after initialization to confirm it is 0.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting the target width of unsigned int on 16-bit assumptions; assuming 32-bit widths everywhere.
Final Answer:
No output.
float a = 0.7;, what will this program print and why?
#includefor loop in C. What does this program print?
#includeswitch statement in C? Note the statement before any case label.
#include
Discussion & Comments