ExamVeda
Login
Home
This question belongs to C Program C Miscellaneous
C Miscellaneous
?

Determine Output:
void main()
{
      float me = 1.1;
      double you = 1.1;
      if(me==you)
            printf("I hate Examveda");
      else
            printf("I love Examveda");
}

Answer & Solution
Correct Answer: Option B

For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.
Rule of Thumb: Never compare or at-least be cautious when using floating point numbers with relational operators (== , >, <, <=, >=,!= ) .

Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Benison Sebastian
Benison Sebastian 6 years ago
Is void main() even legal for C? Many compilers throw compilation error on encountering this.