+ 1
Why output is 10 for c++ and 9 for java
In c++ int a=4; int b; b=a + ++a; cout<<b; //10 In Java int a=4; int b; b=a + ++a; System.out.print(b); //9
1 Answer
0
my guess:
C++
b = a.operator+(++a)
to do the operator function, a must increment, so when the adition is done a is incremented.
java:
execution of an arithmetic expression happens from left to right. so first a is evaluated and then add the incremented one to it, giving 4+5=9, which is assigned to b.
again, its a guess.