Code 1
#include<stdio.h>
int main()
{
float x = 0.1;
if (x == 0.1)
printf("IF");
else if (x == 0.1f)
printf("ELSE IF");
else
printf("ELSE");
}
Output: ELSE IF
Code 2
#include<stdio.h>
int main()
{
float x = 0.5;
if (x == 0.5)
printf("IF");
else if (x == 0.5f)
printf("ELSE IF");
else
printf("ELSE");
}
Output: IF
Why such a difference in the output? I understand that the variable 'x' will be promoted to 'double' type and '0.1' and '0.5' shall be promoted to 'double' type. However, I am not understanding why output of Code 2 is not outputting ELSE IF. Thanks.