πŸ“Š C Programming
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");
}
  • (A) equal
  • (B) not equal
  • (C) the output depends on the compiler
  • (D) None of the above
πŸ’¬ Discuss
βœ… 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

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

πŸ’¬ Discussion


πŸ“Š Question Analytics

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