plz tell fast and Don't spam plz yr fast it's computer u have to find in Java
Answers
Given int x = 10,y why does y = x++ + ++x + x evaluate to a different value than y = ++x + x++ + x in C++ but evaluate to the same value in Java?
y = x++ + ++x + x´=>
C++: Undefined behaviour, you modify an object twice within the same sequence point. The compiler is under no obligation to produce any specific result, anything can happen.
Java: Java evaluates left->right, and does sequencing directly, so x++ is 10, increased to 11 and sequenced, x is now 11, ++x evaluates to 12, and increases and sequences x, x is now 12, then adding x which is still just 12 giving 10 + 12 +12 => 34
y = ++x + x++ + x
C++: Same as before. Undefined behaviour, anything may happen.
Java: evaluates to 11, sequences and x is now 11. x++ evaluates to 11, increased and sequences so x is now 12. x is 12 so => 11 + 11 + 12 => 34