Explain how Output comes out to be 6 ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Explain how Output comes out to be 6 ?

#include <stdio.h> int main() { int i = 3; if(!i) i++; i++; if (i==3) i += 2; i += 2; printf("%d",i); return 0; }

8th Jun 2021, 2:25 PM
Tejas Raut
3 Answers
+ 2
//read comments.... #include <stdio.h> int main() { int i = 3; if(!i) //this becomes false, i++; //so it won't execute.. i++;. //this executes so I=4 now if (i==3) //4==3 false i += 2; //it won't execute i += 2; //it executed so I=4+2=6 printf("%d",i); //here it prints 6 return 0; } //Is it clear? edit: !i=>!3 => false, generally any number other than 0 is true, so negating it becomes false..
8th Jun 2021, 2:29 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 Thanks for the answer 🙂 It was a Quiz Challenge Question
8th Jun 2021, 2:39 PM
Tejas Raut
+ 1
Yes.. You're welcome...
8th Jun 2021, 2:42 PM
Jayakrishna 🇮🇳