Click here to Skip to main content
15,902,840 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
For manual calculation getting 64 but in turbo C complier getting 70 and in Java 64 how it varies can anyone explain

What I have tried:

If taking x=10 by doing the manual calculation getting the answer 64 but in complier getting 70 how is it possible
Posted
Updated 2-Jun-18 23:06pm

Simple: Why does x = ++x + x++ give me the wrong answer?[^]

BTW: in future, don't put your code as the subject line - that's what "What I have tried" is there for. The subject line should be short and sweet, and quick overview of the problem in English as much as possible. Perhaps "x++ giving wrong answer" or similar?
 
Share this answer
 
You are in gray zone: the code is legal, but unpredictable.
C++
y=x++ + ++x + ++x + ++x + ++x;

The compiler is free to reorder what is in this code.
for x=10, y can be anywhere between 50 and 75.
The only advice is: never mess with multiple increment/decrement operations in a single line of code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900