- 1

What is the output of this code? #include <stdio.h> int main() { do { printf("Hi"); } while(5,3,0); return 0; }

Please explain the logic how the output is 'Hi'

26th Oct 2020, 6:22 AM
Suman Kumar Dey
Suman Kumar Dey - avatar
1 Answer
+ 3
The comma operator evaluates both of its arguments in turn, throwing away the result, except for the last. The last evaluated expression determines the result of the entire expression. https://stackoverflow.com/questions/41611557/c-programming-comma-operator-within-while-loop So it's like you have just while( 0 ); The do{} prints "Hi" and the while never repeats.
26th Oct 2020, 8:59 AM
Davide
Davide - avatar