Since while loop terminates its execution for false expression, despite following are giving different outputs. Unable to trace
#include <stdio.h>
int main()
{
//code snippet 1
while(0){
;
}
printf("C");
return 0;
}
this gives output
c
and
#include <stdio.h>
int main()
{
//code snippet 2
while(printf("%d")){
;
}
printf("c");
return 0;
}
this gives output
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Since printf() function returns the number of characters printed, and no character is being printed, therefore it should not result in an infinite loop as 0 has the logical value false.