Question: What will be output when you will execute following c code?#include<stdio.h>
void main(){
int a=10;
if(printf("%d",a>=10)-10)
for(;;)
break;
else;
}
A
B
C
D
E
It will print nothing
B
0
C
1
D
Compilation error: Misplaced else
E
Infinite loop
Note: Return type of printf function is int. This function return a integral value which is equal to number of charcters printf function will print on console.
Operator >= will return 1 if both operands are either equal or first operand is grater than second operand. So a>=10 will return 1 since a is equal to 10.Thus printf function will print 1. Since this function is printing only one character so it will also return 1. So, printf("%d",a>=10) - 10
= 1 - 10
= -9
Since -9 is non-zero number so if(-9) is true condition hence if clause will execute which contains an infinite loop but due to break keyword it will come out of loop.