Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   printf() unusual behavior (http://www.go4expert.com/forums/printf-unusual-behavior-t12877/)

rex sinha 12Aug2008 13:05

printf() unusual behavior
 
Hi friends...

void main()
{
float a=2.45;
printf("%d%f",a,a);
}
what would be the output of above mentioned question and why?
plz. help me.
thanx in advance.

shabbir 12Aug2008 14:37

Re: printf() unusual behavior
 
Try running and see what it gets?

rex sinha 12Aug2008 16:04

Re: printf() unusual behavior
 
thanx...
It gives unexpected output...
let me tell u an example

void main()
{
float a=0.7;
printf("%d%f",a,a);
}
output :---------
0
and
0.0000000

arkangel 13Aug2008 00:44

Re: printf() unusual behavior
 
what about this

printf(%d%f,(int) a,a);

shabbir 13Aug2008 09:37

Re: printf() unusual behavior
 
Change your declaration to
float a = 0.7f;
and see whats the output.

faizulhaque 13Aug2008 13:47

Re: printf() unusual behavior
 
nothing is heppened.
it b/c float takes the 4bytes in stact memory of type floating point, but if our program give him a integer value than it's will converted into 0 or 0.00000000,


All times are GMT +5.5. The time now is 23:37.