int main(){
float f=8.0;
if(f==8.0)
printf("good");
else
printf("bad");
}
what is the answere and explain it?

Answers were Sorted based on User's Feedback



int main(){ float f=8.0; if(f==8.0) printf("good"); else printf("bad"); } ..

Answer / pratima

BAD

Is This Answer Correct ?    10 Yes 6 No

int main(){ float f=8.0; if(f==8.0) printf("good"); else printf("bad"); } ..

Answer / c++ coder

Answer is "bad"
reason being, that when 8.0 is stored into the float
variable , it is never stored exactly as 8.0 because of
precision. Thus the comparsion will never evaluate to true.
It is always recommended not to do float, double
comparsions like this. :)

Is This Answer Correct ?    2 Yes 0 No

int main(){ float f=8.0; if(f==8.0) printf("good"); else printf("bad"); } ..

Answer / jayaraj.s

good is the result. because we declare and compare the same
value in the program.so alwaye if condition is true. we no
need to put else condition for these type of comparisions.

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More C Interview Questions

diff between exptected result and requirement?

0 Answers   HCL,


What is structure of c program?

0 Answers  


Is there a way to jump out of a function or functions?

0 Answers  


Why is c platform dependent?

0 Answers  


What is linear search?

0 Answers  






What are external variables in c?

0 Answers  


what is structuer?

4 Answers   LG Soft, Wipro,


How can you print HELLO WORLD without using "semicolon"?

7 Answers   HCL, Infosys,


write a program to remove duplicate from an ordered char array? in c

2 Answers  


what is the stackpointer

2 Answers  


What do you mean by Recursion Function?

0 Answers   Hexaware,


While compiling a c program,graphics header files are not including in my program..eg: <graphics.h>,what may be the problem...is there any environment settings exists.

2 Answers  


Categories