Hi all,
I'm new to java. Please help anyone regarding this question....
int a=1;
a += ++a + a++;
compiler gives answer as 5.
but according to the logic it should give answer 7.
please anyone explain this....
thanks millions.......
Printable View
Hi all,
I'm new to java. Please help anyone regarding this question....
int a=1;
a += ++a + a++;
compiler gives answer as 5.
but according to the logic it should give answer 7.
please anyone explain this....
thanks millions.......
Basically there are four operators.
1. Compound operatos
2. Prefix increment
3. Postfix increment
4. Addition
Do you know about those?
ya, i know.....
but i am confuse with the order of execution. still im didnt get the answer.
Postfix operators are executed once the process is finish. Prefix operators are executed before the process finish.
Execution start from left to right.Code:a += ++a + a++;
a = a + ++a + a++;
a = a + (++a) + (a++);
Answer is 5, hope it's clear.Code:a = a + (++a) + (a++);
// Post fix not effected, so
a = a + (++a) + (a);
a = 1 + (2) + (2);
Hi,
Ques->a += ++a + a++;
Ans->I think,the evaluation start from left to right.
a=a + ++a + a++;
a=1 + ++a + a++;
a=1 + 2 + a++;
a=1 + 2 + 2
a=5
Hi Deepa,
The above answer is correct..