Please explain this!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Please explain this!!

Please explain how for loop execute in this case and why the output is 'a'. for(putchar('a'); putchar(0);putchar('c')) putchar('b') >>a

9th Oct 2018, 3:36 PM
Shruti
Shruti - avatar
1 Answer
+ 3
putchar returns the character written so converting to a while loop so you can better see what actually happens: 1: putchar('a'); 2: while (putchar(0)) { 3: putchar('b'); 4: putchar('c'); 5: } 6: line 1 outputs 'a' line 2 outputs '\0' and since it's value is 0 skips the loop to line 6
10th Oct 2018, 4:21 AM
John Wells
John Wells - avatar