By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,849 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,849 IT Pros & Developers. It's quick & easy.

What is the ouptput of this program ?

P: 1
Saw this question :
What is teh output of the program ??
main()
{
printf("%f",sqrt(36.0));


Choice :
a 6.0
b 6
c 6.000000
d soem absurd result

The soln to this has been given as D .. i dont get why tho

Also ami write in assuming that the compiler takes 36.0 as a double and not a float ??

Thanks
Nov 4 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
Well the only mistakes I see are that

a. main is not returning int which invokes undefined behaviour and anything could happen

b. there is no \n at the end of the printf statement so the program is not required to flush the printed value to the screen.


36.0 is a double constant, a float constant would be 36.0F

sqrt accepts and returns double and %f is the indicator to printf to expect a double (there is no indication to expect a float because float are passed as double by default).
Nov 6 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.