Computer Science, asked by rachel0502, 7 months ago

int x=5, y=8, z=10; 1. int r= x++ - y--/++x - ++x/--y , 2. int z= ++z - ++y - ++x/++z - y--

Answers

Answered by supratik0109
0

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

Similar questions