main()
{
float a=8.8;
double b=8.8;
if(a==b)
printf("Equal");
else
printf("not equal");
getch();
}
what is the output?
with reason
Answer Posted / rakesh
It will print "not equal". Reason is the difference in
precision of the numbers. ie numbers like 8.8 or 8.1 can't
be stored with complete precision in binary sysetm since
it's mantissa part will not end but continues with a
series. So value calculated for single precision(float)
number will be slightly different from the value calculated
for double precision (double) number. To verify this use
gcc and gdb in linux.
If you try with numbers 8.25, 8.5 or 8.75 the program will
print "equal" since the mantissa part ends with in the
precision.
I think this has nothing to do with compiler version or
inabilty of comparision.
| Is This Answer Correct ? | 10 Yes | 0 No |
Post New Answer View All Answers
What is array in C
Write a program to print numbers from 1 to 100 without using loop in c?
What is "Duff's Device"?
What are the types of pointers?
Explain what is the benefit of using const for declaring constants?
What is the time and space complexities of merge sort and when is it preferred over quick sort?
Explain zero based addressing.
write a c program in such a way that if we enter the today date the output should be next day's date.
What is an endless loop?
Can a void pointer point to a function?
Is boolean a datatype in c?
What is the significance of an algorithm to C programming?
What does struct node * mean?
Why is c known as a mother language?
Write a program to find the biggest number of three numbers in c?