What is the output of code? oid main () { int x = 33, y, z; z = x++ + 17; y =…

2021

What is the output of code? oid main () { int x = 33, y, z; z = x++ + 17; y = ++z - ++x; cout << "x=" << x << " y=" << y << " z=" << z; }

  1. A.

    x = 34 y = 17 z = 51

  2. B.

    x = 35 y = 16 z = 51

  3. C.

    x = 34 y = 16 z = 50

  4. D.

    x = 35 y = 17 z = 51

Attempted by 140 students.

Show answer & explanation

Correct answer: B

Initial values:

x = 33

Step 1:

z = x++ + 17;

x++ is post-increment:


  • First use current value of x

    Then increment x

So:

z = 33 + 17 = 50

After execution:

x = 34
z = 50

Step 2:

y = ++z - ++x;

++z is pre-increment:

z = 51

++x is pre-increment:

x = 35

Now:

y = 51 - 35 = 16

Final values:

x = 35
y = 16
z = 51

Therefore, the output is:

x = 35  y = 16  z = 51

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs