Bird
0
0

What will be the output of this C code?

medium📝 Predict Output Q4 of 15
C - Variables and Data Types
What will be the output of this C code?
unsigned int x = 4294967295;
long int y = x;
printf("%ld", y);
ACompilation error
B4294967295
C0
D-1
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable types and values

    'x' is unsigned int with max 32-bit value 4294967295; 'y' is long int.
  2. Step 2: Assign unsigned int to long int

    Value fits in long int (usually 64-bit), so 'y' holds 4294967295.
  3. Step 3: Print 'y' with %ld

    Output prints 4294967295 as expected.
  4. Final Answer:

    4294967295 -> Option B
  5. Quick Check:

    Unsigned to long int preserves value [OK]
Quick Trick: Unsigned int fits in long int, prints same value [OK]
Common Mistakes:
  • Expecting negative due to sign
  • Assuming overflow
  • Using wrong printf specifier

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes