0

#include <stdio.h> int main() { do{ printf("Hi"); }while(5,3,0); return 0; }

Why Hi is printed only once and Not Three times?? https://code.sololearn.com/cavzumMug000/?ref=app

10th Feb 2021, 7:40 PM
Sanjeeb Kumar Rai
Sanjeeb Kumar Rai - avatar
7 Réponses
+ 3
Because 5,3,0 makes no sense and therefore compiler gives an error . The only reason it ran was due to do statement. Following code will print 3 times, int i=3; do{ printf("Hi"); }while(--i); return 0; }
10th Feb 2021, 7:44 PM
Abhay
Abhay - avatar
+ 4
Here's info about comma operator. May it helps you understand why the code is acting as it does. https://sillycodes.com/comma-operator-in-c-programming/
10th Feb 2021, 9:23 PM
Ipang
+ 2
#include <stdio.h> int main() { int i =0; do{ printf("Hi\n"); i++; }while(i<3); return 0; }
10th Feb 2021, 10:03 PM
Halgord Darbandi
Halgord Darbandi - avatar
+ 2
Sanjeeb Kumar Rai Sorry bro, yes that one is not working. I have put another link that may help you understand this comma operator there ☝
12th Feb 2021, 8:43 AM
Ipang
+ 1
Thanks a lot
10th Feb 2021, 7:45 PM
Sanjeeb Kumar Rai
Sanjeeb Kumar Rai - avatar
+ 1
Ipang The link seems to be broken
12th Feb 2021, 7:05 AM
Sanjeeb Kumar Rai
Sanjeeb Kumar Rai - avatar
+ 1
Ipang Thanks bro
12th Feb 2021, 4:57 PM
Sanjeeb Kumar Rai
Sanjeeb Kumar Rai - avatar