x=10,find x-=x++*++x+2
This question is from Operators in JAVA
Please explain
Please answer it correctly
Please answer it very fast
poojavyas171090:
10 * 12 + 2 =122
Answers
Answered by
3
HEYA!!
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
HOPE IT HELPS ✌
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
HOPE IT HELPS ✌
Answered by
8
x=x-x++*++x+2
=10-10*12+2
=120-10+2
=120-12
=108 ....Answer
Hope it helps you my friend ...
Please mark it as brainliest ....
=10-10*12+2
=120-10+2
=120-12
=108 ....Answer
Hope it helps you my friend ...
Please mark it as brainliest ....
Similar questions