Temporary C++ amnesia 8|

Status
Not open for further replies.

NikhilVerma

Padawan
This is simple....
Do you see the i++ part...

it's like this ++i makes the value of i 6
then iafter the division make the division of 6 with 6 and you get one...
which is stored in i
then the ++ makes it two....

Tell me if you didn't understand....
 

sakumar79

Technomancer
The answer is simple
i=(++i)/(i++)
First, ++i => i=6
Then, i++=> use six, and AT THE END OF THIS STATEMENT, ADD 1 to i
i=6/6=1
NOW, add 1 to i =>i=2

Hope that helps...
Arun
 

sakumar79

Technomancer
Hi Nikhil,
It sure was a coincidence... What are the odds, 2 people posting the answer at the same time and in similar manner!!!

Harmax,
If you read my post or Nikhil's post carefully, and rework with any value of i manually, u will see the reason. It is not that division has higher priority over '(', but that it has higher priority over post-increment operator.

DKant,
Glad we could help...

Arun
 
Status
Not open for further replies.
Top Bottom