Home » C Programming » Operators » Question
  1. Which of the following statements are correct about the program given below?
    #include <stdio.h>
    int main ( )
    {
    float x = 2.8, y = 2.88;
    if (x = y)
    printf ("x and y are equal\n");
    else
    printf ("x and y are not equal\n");
    return 0;
    }
    1. The output of the program would be "x and y are equal".
    2. The statement if (x = y) would report a compilation error.
    3. Floats cannot be compared using if.
    4. switch should be used to compare floats.
    5. Conditional operates should be used to compare floats.
Correct Option: A

There is a non zero assignment value inside "if" so, it if condition will be true hence The output of the program would be "x and y are equal".



Your comments will be displayed only after manual approval.