Skip to main content
added 316 characters in body
Source Link

You should also be aware that the behaviour of postincrement/decrement operators is different in C/C++ and Java.

Given

int a=1;

 int a=1; 

in C/C++ the expression

a++ + a++ + a++

 a++ + a++ + a++ 

evaluates to 3, while in Java it evaluates to 6. Guess why...

This example is even more confusing:

cout << a++ + a++ + a++ << "<->" << a++ + a++ ; 

prints 9<->2 !! This is because the above expression is equivalent to:

operator<<( operator<<( operator<<( cout, a++ + a++ ), "<->" ), a++ + a++ + a++ ) 

You should also be aware that the behaviour of postincrement/decrement operators is different in C/C++ and Java.

Given

int a=1;

in C/C++ the expression

a++ + a++ + a++

evaluates to 3, while in Java it evaluates to 6. Guess why...

You should also be aware that the behaviour of postincrement/decrement operators is different in C/C++ and Java.

Given

 int a=1; 

in C/C++ the expression

 a++ + a++ + a++ 

evaluates to 3, while in Java it evaluates to 6. Guess why...

This example is even more confusing:

cout << a++ + a++ + a++ << "<->" << a++ + a++ ; 

prints 9<->2 !! This is because the above expression is equivalent to:

operator<<( operator<<( operator<<( cout, a++ + a++ ), "<->" ), a++ + a++ + a++ ) 
Source Link

You should also be aware that the behaviour of postincrement/decrement operators is different in C/C++ and Java.

Given

int a=1;

in C/C++ the expression

a++ + a++ + a++

evaluates to 3, while in Java it evaluates to 6. Guess why...