+ 9
Find the result
find the value of x : int y=10; int x=++y*(y++ +5); I expected the value of x to be 180.((10+5)*12). It is showing 176.(11*16).
6 odpowiedzi
+ 9
yes it is right java compiler works from left to right for statement
x=++y (y++ +5);
It will first increment the statement and convert it into value form as
x = 11 (11+5);
x = 11*(16);
x = 176
+ 8
Meet Mehta ,
shouldn't the part inside the parenthesis be operated first. They have the highest order in operator precedence.
+ 8
thanks to everyone
+ 4
the simple thing is the post fix and prefix operators will be from left to right.
simply
run these type of questions and get the answer
this and only this pattern is followed.
😊😉
thnx
+ 3
yeah it shows right...
when u use pre increment variable will increment first and then take part in calculation and in post increment it first take part in oprration with its initial value and then increment after operation ends...
so here
y is incremented first to 11
11*(11+5)
11*16=176
and after that y value increment to 12
+ 1
y=10
x = ++y (11 pre increment)
*(y++ (11 post increment) + 5).
x = 11 * (11 + 5).
=11*16
=176.
Hope this helps ☺️☺️.