008# puzzle on c

@dholey (1383)
India
February 6, 2007 4:10am CST
WHAT WILL BE THE OUTPUT .. EXPLAIN IT WITH REASON ........ (for turbo c / turbo c++ IT MA HAVE OTHER OUTPUT IN OTHER COMPILER ) void main () { float a=0.9; if(a
1 person likes this
5 responses
@kingadnan (1538)
• Pakistan
17 Feb 07
yeah! nice its a common sense there is a if loop, so there result is FALSE because there is a!
1 person likes this
@dholey (1383)
• India
22 Feb 07
very first thing "if" is not a loop , second thing your answer is wrong ..... check it on c /c++ compiler .....
@dholey (1383)
• India
28 Feb 07
dont feel sorry man ... ther is nothing that human can not learn .... i have seen that you are good at java ... so you can easily learn c..... so keep it up .....
@kingadnan (1538)
• Pakistan
27 Feb 07
sorry dholey uncle it was a typing mistake there is a condition of if, and if my answer is wrong, sorry, i don't know C language.
• India
8 Feb 07
FALSE. When comparing, 0.9 is taken as a double instead of float so they are not equal. But according to this comparison, it would always print FALSE... If the comparison was for equality(==) then it would print TRUE if 0.9 was casted into float data type. I don't have a compiler in my comp, so I am not able to compile it and see the output..Am I right?
@dholey (1383)
• India
8 Feb 07
i know you have tested the code .... hoho ..
• India
8 Feb 07
I guess i change my mind! It's TRUE i guess... hehehehe
• India
8 Feb 07
Hey Buddy! I don't ve a compiler! what's the output? I would really like to know..
• India
6 Feb 07
FALSE is the output. cuz, "a" is of float datatype, initialized to 0.9 but, in loop, we r checking whether a
@dholey (1383)
• India
7 Feb 07
i can only say ... RUN IT ON YOUR PC ........
@dholey (1383)
• India
7 Feb 07
and one more thing 0.9 will not be taken as integer .....
• India
9 Feb 07
Hi Output is obviously true as the condition get satisfied. I also verified in TC compiler. But as you told in some compilers even though we assign a=.9 when it comes to the condition it compares it with 0.899999 up to six mantissa. So 0.899999
@dholey (1383)
• India
10 Feb 07
nice to have your post .. please get time to see more puzzles from my profile....
• United States
8 Feb 07
I dunno... I probably will have to put it in the webpage hyperlink and find out if it works....