Q. What is the output of the following C program?

Code:
#include <stdio.h>

int main()
{
    float a = 0.1;
    if (a == 0.1f)
        printf("equal\n");
    else
        printf("not equal\n");
}
  • (A) equal
  • (B) not equal
  • (C) the output depends on the compiler
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) equal
Explanation: To check the equality of a float number you have to follow the value with the f letter. The output is as follows:

$gcc prog2.c
$ a.out
equal
Explanation by: Admin
To check the equality of a float number you have to follow the value with the f letter. The output is as follows:

$gcc prog2.c
$ a.out
equal

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
188
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Admin
Publisher
πŸ“ˆ
88%
Success Rate