Step by step process to evaluate the corresponding expression........
int a=2;
a+=a++;
a+=(a++); //value of a is 2
a=a+(a++); //value of a is 2
//remeber the evaluation of expression is from left to right
a=2+(a++); //value of a is 2
a=2+(2); //value of a is 3 as b=a++; then b=2 and a=3
a=2+2;
a=4
The above process is in
java as evaluation of expression is
left to right
But in some languages like
c,c++ the evaluation of expression is from right to leftthen the output would be 5 as follows
a+=a++;
a=a+(a++); //value of a=2
a=a+(2);//value of a=3
a=3+2;
a=5;
in case of assemblers
a+=a++;
a=a+a++;
a=a+a+1;
a=2+2+1;
a=5;
So the output is 4 in case of Java or .Net and the output is 5 with C,C++ -----