int b=9; b = b +(b=3); System.out.println(b); Output??
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
0
What do you get when you compile and run it? What don't you understand about the answer you get? Please show some effort that you have tacked the problem.
Originally posted by Barry Gaunt: What do you get when you compile and run it? What don't you understand about the answer you get? Please show some effort that you have tacked the problem.
I excuted and got the output is 12. But i want to know the flow of excution happening here
b=b+(b=3)
According to operator precedence (b=3) has to excute first rt?
so b= 3 + 3 right?
So answer is 6 ???
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
0
No, take a look at how b = b + (b=3) is performed. First the value of b(9) is pushed on the stack. Then the value of evaluating b=3 (3) is pushed on the stack.
So the stack (from the top down) contains 3 and 9. The result is the sum of those two stack entries (12), and that gets assigned to b.