Q. What is the output of the following C program?
Code:
#include <stdio.h>
int main()
{
float a = 0.1;
if (a == 0.1)
printf("equal\n");
else
printf("not equal\n");
}
β
Correct Answer: (B)
not equal
Explanation: The default value 0.1 is a value of type double which has a different representation than the float, resulting in inequality even after conversion. The output is as follows:
$gcc prog1.c
$ a.out
not equal