Question:What will be output when you will execute following c code?#define True 5==5
#include<stdio.h>
void main(){
if(.001-0.1f)
printf("David Beckham");
else if(True)
printf("Ronaldinho");
else
printf("Cristiano Ronaldo");
}
Choose all that apply:
A David Beckham
B Ronaldinho
C Cristiano Ronaldo
D Warning: Condition is always true
E Warning: Unreachable code
+ ExplanationAs we know in c zero represents false and any non-zero number represents true. So in the above code:
(0.001 – 0.1f) is not zero so it represents true. So only if clause will execute and it will print: David Beckham on console.
But it is bad programming practice to write constant as a condition in if clause. Hence compiler will show a warning message: Condition is always true
Since condition is always true, so else clause will never execute. Program control cannot reach at else part. So compiler will show another warning message:
Unreachable code