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


Please Help Members By Posting Answers For Below Questions

Not all reserved words are written in lowercase. TRUE or FALSE?

710


What is hungarian notation? Is it worthwhile?

680


List some of the static data structures in C?

749


What type of function is main ()?

572


What functions are in conio h?

643






What is the right type to use for boolean values in c?

570


Write a c program to demonstrate character and string constants?

1672


When should the volatile modifier be used?

667


What is context in c?

528


Is that possible to store 32768 in an int data type variable?

676


What kind of structure is a house?

540


Explain how can you avoid including a header more than once?

585


What is structure in c definition?

562


How can I handle floating-point exceptions gracefully?

615


What are the two types of structure?

562