int i=5,j; j=(++i)+(++i); | SoloLearn: Learn to code for FREE!

+2

int i=5,j; j=(++i)+(++i);

The output of this code in Java and c compiler is different . Can anyone explain . Why is it so ?

7/1/2019 9:39:06 AM

parag sahu

6 Answers

New Answer

+8

It'll always be the same answer for C: undefined behavior https://stackoverflow.com/questions/949433/why-are-these-constructs-using-pre-and-post-increment-undefined-behavior

+9

Anna How nice it would be to have a bot to answer so many of these repeated questions? I imagine this must be a mind bending discovery for people stumbling upon undefined behavior for the first time. Heck... I still remember thinking... "What the Fraggle Rock?" When I first stumbled upon it. It's like my mind was blown... 🤯 How could this be? 🤣 But, after seeing this happen to so many people for their first time, over and over and over again, it's sort of become like the movie Groundhog Day. 🤣

+4

David Carroll "Fraggle Rock" - Haven't heard that one before. Had to look It up. It seems you are a child of the 80s. 😄

+4

Thnk u so much Anna 😊

+3

Michael U. Indeed sir... I am. 😉 I was 5 yrs old in 1980, so yep. 😁

+2

ANSWER-13 first ++i is preincrement so the value of i is 6 another one also preincrement ++i the i value becomes 7 finally 6+7=13 THANK YOU