printf() unusual behavior

rex sinha's Avatar, Join Date: Jun 2008
Newbie Member
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's Avatar, Join Date: Jul 2004
Go4Expert Founder
Try running and see what it gets?
rex sinha's Avatar, Join Date: Jun 2008
Newbie Member
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's Avatar, Join Date: Aug 2008
Light Poster
what about this

printf(%d%f,(int) a,a);
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Change your declaration to
float a = 0.7f;
and see whats the output.
faizulhaque's Avatar, Join Date: May 2008
Skilled contributor
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,