What is the difference between ++i and i++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the difference between ++i and i++?

i++ = first assign then increment //postfix increment ++I = first increment then assign //prefix increment Example - //postfix increment i= 4; i++; Printf("%d",i); //prefix increment i= 4; ++i; Printf("%d",i); GUESS THE OUTPUT 😌

31st Aug 2021, 12:56 PM
Ankita Malik
Ankita Malik - avatar
2 Answers
+ 1
Well, the output would be an error. You forgot the semicolons and to declair i and c is case sinsitive. If you fix all those errors, the output for each is 5 https://code.sololearn.com/c8h2mc0PpwJ1/?ref=app The difference would be if you had: printf("%d\n",i++); And: printf("%d",++i); https://code.sololearn.com/cVTHIi06E3F2/?ref=app
31st Aug 2021, 1:16 PM
Brain & Bones
Brain & Bones - avatar
+ 1
Updated the code 💙! Thanks
31st Aug 2021, 1:53 PM
Ankita Malik
Ankita Malik - avatar