πŸ“Š C Programming
Q. Determine Output:
Code:
void main()
{
      float me = 1.1;
      double you = 1.1;
      if(me==you)
            printf("I hate MCQ Buddy");
      else
            printf("I love MCQ Buddy");
}
  • (A) I hate MCQ Buddy
  • (B) I love MCQ Buddy
  • (C) Error
  • (D) None of These
πŸ’¬ Discuss
βœ… Correct Answer: (B) I love MCQ Buddy

Explanation: 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 (== , >, <, <=, >=,!= ) .

Explanation by: Prashant
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 (== , >, <, <=, >=,!= ) .

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
196
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Prashant
Publisher
πŸ“ˆ
95%
Success Rate