Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use a float variable f and initialize it with 3.3. Later I tried to print output using %d format specifier but I got 0 as output. Now my question is why I got 0 but not 3?

What I have tried:

void main()
{
float f=3.3;
printf("value of f is : %d",f);
gecth();
}
Posted
Updated 15-Aug-18 6:14am

1 solution

Because you are trying to print a float value as an integer. (The actual result you get will be system dependant, you can't rely on it being zero either - my compiler gives me "12"!)
Try:
C++
printf("value of f is : %f\n",f);
Or
C++
printf("value of f is : %d\n",(int)f);
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900