In this code, floating values are same, but their data types are different. The compiler checks and declares them ‘not equal’ on the basis of data types.
#include <stdio.h>
int main()
{
float a=21.2;
double b=21.2;
if (a==b)
printf("Both values are equal");
else
printf("Both values are not equal");
return 0;
}
Output
Both values are not equal
"Both values are equal", you are thinking the same. But the output says just opposite. "Both are not equal" , this is because, in floating point number like float, double, long double, the values cannot be predict exactly, these are depending on the number of bytes. So the compiler differences between 21.2 and 21.2.
In this code, floating values are same, but their data types are different. The compiler checks and declares them ‘not equal’ on the basis of data types.
Output
"Both values are equal", you are thinking the same. But the output says just opposite. "Both are not equal" , this is because, in floating point number like float, double, long double, the values cannot be predict exactly, these are depending on the number of bytes. So the compiler differences between 21.2 and 21.2.
need an explanation for this answer? contact us directly to get an explanation for this answer