Bird
0
0

What is the output of this code?

medium📝 Predict Output Q5 of 15
C - Variables and Data Types
What is the output of this code?
short int a = 32767;
a++;
printf("%d", a);
A32768
BCompilation error
C0
D-32768
Step-by-Step Solution
Solution:
  1. Step 1: Understand short int range

    short int max value is 32767; incrementing causes overflow.
  2. Step 2: Overflow behavior

    Overflow wraps to minimum value -32768 in signed short int.
  3. Step 3: Print value

    Output is -32768.
  4. Final Answer:

    -32768 -> Option D
  5. Quick Check:

    Short int overflow wraps to negative min [OK]
Quick Trick: Short int max +1 wraps to negative min [OK]
Common Mistakes:
  • Expecting 32768 (out of range)
  • Ignoring overflow wrap
  • Using unsigned range

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes