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

Define a structure to store the record of library. The record must consist of at least following fields: Title, Author, Edition, Price, Publisher, and Category. -Define functions authorSearch ( ), TitleSearch ( ) and CategorySearch ( ) to search a book with respect to author, title and category. [There can be more than one book, written by one author, in one category]

2 Answers  


What are types of structure?

0 Answers  


Can a pointer point to null?

0 Answers  


Why is python slower than c?

0 Answers  


How does free() know how many bytes to free?

8 Answers  


How to explain the final year project as a fresher please answer with sample project

0 Answers  


Is it better to use a macro or a function?

0 Answers  


DIFFERNCE BETWEEN THE C++ AND C LANGUAGE?

2 Answers   Wipro,


If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?

0 Answers  


What is the process of writing the null pointer?

0 Answers  


Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record

0 Answers   Wipro,


Explain how can I remove the trailing spaces from a string?

0 Answers  


Categories