Bird
0
0

What is the output of this C code?

medium📝 Predict Output Q4 of 15
C - Operators and Expressions
What is the output of this C code?
int a = 2;
printf("%d %d", a++, ++a);
A2 3
B3 3
C2 4
D3 4
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate post-increment and pre-increment order

    In printf("%d %d", a++, ++a);, a++ uses 2 then increments to 3; ++a increments 3 to 4 then uses 4.
  2. Step 2: Determine printed values

    First %d prints 2 (original a), second %d prints 4 (after pre-increment).
  3. Final Answer:

    2 4 -> Option C
  4. Quick Check:

    Post-increment uses old value, pre-increment uses new value [OK]
Quick Trick: Post-increment uses old value; pre-increment uses new value [OK]
Common Mistakes:
  • Assuming increments happen left to right strictly
  • Confusing values printed by post- and pre-increment
  • Ignoring side effects in function arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes