Bird
0
0

What is the value of variable y after this code runs?

easy📝 Conceptual Q2 of 15
C - Operators and Expressions
What is the value of variable y after this code runs?
int x = 3;
int y = ++x;
A3
B5
C2
D4
Step-by-Step Solution
Solution:
  1. Step 1: Understand pre-increment operator

    The pre-increment operator ++x increases x first, then uses the new value.
  2. Step 2: Apply to given code

    x starts at 3, ++x makes it 4, so y is assigned 4.
  3. Final Answer:

    4 -> Option D
  4. Quick Check:

    Pre-increment increments before assignment [OK]
Quick Trick: Pre-increment adds 1 before using value [OK]
Common Mistakes:
  • Thinking pre-increment uses old value
  • Mixing pre- and post-increment effects
  • Ignoring operator position

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes