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


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


It'll always be the same answer for C: undefined behavior


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. 🤣


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


Thnk u so much Anna 😊


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


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