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

prinf formatting problem

P: 1
printf("%d", 12.0 / 8);

Why does the above print 0 and not 1.

- SSK
Mar 14 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,510
printf("%d", 12.0 / 8);

Why does the above print 0 and not 1.

- SSK
the expression 12.0 / 8 yeilds a double result which you attempt to print as a int using the %d conversion specification. If you cast the result to an int it will print correctly, e.g.
Expand|Select|Wrap|Line Numbers
  1. printf("%d", (int) (12.0 / 8));
Mar 14 '07 #2

Post your reply

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