Bird
0
0

Consider this code:

hard📝 Application Q9 of 15
C - Operators and Expressions
Consider this code:
int x = 0;
int y = x++ + ++x + x-- + --x;

What is the value of y after execution?
A6
B4
C5
D7
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate each term step-by-step

    Start with x=0.
    - x++: uses 0, then x=1
    - ++x: x=2, uses 2
    - x--: uses 2, then x=1
    - --x: x=0, uses 0
  2. Step 2: Sum all values

    Sum = 0 + 2 + 2 + 0 = 4
  3. Step 3: Re-check increments and decrements

    After x-- x=1, then --x decrements to 0.
    Values used: 0 + 2 + 2 + 0 = 4
  4. Final Answer:

    4 -> Option B
  5. Quick Check:

    Track x changes carefully with each operator [OK]
Quick Trick: Track variable changes stepwise for combined increments [OK]
Common Mistakes:
  • Adding incremented values incorrectly
  • Ignoring side effects order
  • Assuming all increments happen before sum

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes