option B is right answer (Upvote it if it is helpfull)
B. z = (x++) + (++y);
here we need to perform stack evaluation
so for the stack evalution the steps are
- pre increment/ decrement
- substitute the value
- Assign the values
- post increment/ decrement
let x=1 y=2
then by,
y=y+1; → y = 2 + 1 = 3 ;
z=x+y; → z = 1 + 3 = 4 ;
x=x+1; → x = 1 + 1 = 2 ;
after operations x=2,y=3,z=4………………….….,,,,….(1)
option B : x=1,y=2,z=3;
z = (x++) + (++y);
z = 1 + 3
z = 4
after assignment of value in z
the value of y = 3 , x= 2 ,z=4 ………………………………...(2)
from eqn (1) & (2),
x,y,z values are same