Data Type MCQ 1 : Comparing Floating Point Value with Double in C

April 4, 2010 2 Comments » Hits : 75






In C Programming (Multiple Choice Question 1 ) Comparing Floating Point Value with Double


#include<stdio.h>
void main()
{
float num1 = 1.1;
double num2 = 1.1;
if(num1==num2)
    printf("Stanford");
else
    printf("New Delhi");
}

Options : 

  1. Stanford
  2. New Delhi
  3. Compile Error
  4. Run Time Error



Why & How ?

  • Float store floating point numbers with 8 place accuracy
    and requires 4 bytes of Memory.
  • Double has 16 place accuracy having size of 8 bytes
  • For floating point numbers (float, double, long double) the values cannot be predicted exactly.


  • pavan4u

    can anyone help me getting answer for data type between int num1 and float num2 and is output going to vary for if(num1==num2) from if(num2==num1)? thanks for helping!

  • Admin

    In short –
    float num1 = 16;
    int num2=16;

    is stored as 15.9999999… and so on

    so num1 != num2