find the output of the following:
x = 10;
y = ++x + x++ * x++
Answers
Answered by
1
Answer:
int x=10,y=0;
y= ++x+x++*x++
=11+11*12
=11+132
=143
How it executed:
variable x is declared and initialized with value 10 and y is initialised
y=++x + x++*x++
In Java compiler it will divide the problem in two parts
y=++x+(x++*x++)
Step 1:x becomes 11 due to pre increment and the value is incremented to x as 11 so final value becomes 11
y=11+(x++*x++)
Step 2:final value of x is 11 so the value is incremented but the incremented value is not assigned due to post increment hence x remains 11 but the final value of x becomes 12
y=11+(11*x++)
Step 3:final value of x is now 12 so this time also due to post increment the assigned value remains the same
Hence,
y=11+(11*12)
=11+132
=143
Similar questions
Social Sciences,
2 months ago
Physics,
2 months ago
English,
4 months ago
English,
4 months ago
Social Sciences,
11 months ago
Math,
11 months ago