Skip to content
Related Articles

Related Articles

ISRO | ISRO CS 2011 | Question 44
  • Last Updated : 14 May, 2018

In Java, after executing the following code what are the values of x, y and z?

int x,y=10; z=12;
x=y++ + z++;
(A) x=22, y=10, z=12
(B) x=24, y=10, z=12
(C) x=24, y=11, z=13
(D) x=22, y=11, z=13

Answer: (D)


x = y++ + z++;

As in post increment operator, first the value is assigned and then it is incremented, this statement can be re-written as:

x = y + z;
y = y++;
z = z++;

So, the value of x = 10 + 12 = 22, y = 10 + 1 = 11 and z = 12 + 1 = 13.

Option (D) is correct.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :