int i=5,j; j=(++i)+(++i); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 ?

1st Jul 2019, 9:39 AM
parag sahu
parag sahu - avatar
6 Answers
1st Jul 2019, 11:44 AM
Anna
Anna - avatar
+ 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. 🤣
1st Jul 2019, 12:22 PM
David Carroll
David Carroll - avatar
+ 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. 😄
1st Jul 2019, 2:39 PM
Michael U.
Michael U. - avatar
+ 4
Thnk u so much Anna 😊
1st Jul 2019, 5:19 PM
parag sahu
parag sahu - avatar
+ 3
Michael U. Indeed sir... I am. 😉 I was 5 yrs old in 1980, so yep. 😁
1st Jul 2019, 5:12 PM
David Carroll
David Carroll - avatar
+ 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
5th Jul 2019, 4:46 PM
Praveen Kumar