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

write a program to rearrange the array such way that all even elements should come first and next come odd

0 Answers  


What is a pointer?

1 Answers   ADP, IFFCO,


Finding first/last occurrence of a character in a string without using strchr( ) /strrchr( ) function.

2 Answers  


can you change name of main()?how?

3 Answers   HCL, Siemens,


Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)

0 Answers  






related to rdbms query .

2 Answers  


wats SIZE_T meant for?

1 Answers  


Suggesting that there can be 62 seconds in a minute?

0 Answers  


how can i print "hello"

3 Answers  


write a function which accept two numbers from main() and interchange them using pointers?

3 Answers  


how can use subset in c program and give more example

0 Answers  


What is double pointer?

0 Answers  


Categories