A

Admin • 833K Points
Coach

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
");
else
printf("not equal
");
}
  • (A) equal
  • (B) not equal
  • (C) the output depends on the compiler
  • (D) None of the above
  • Correct Answer - Option(B)
  • Views: 26
  • Filed under category C Programming
  • Hashtags:

Explanation by: Admin

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

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.