Friday, January 6, 2012
What happens if we try to display an int with %f or a float with %d?
If you try to do this you will most likely get completely nonsensical values or zeros displayed on the screen. This is a common error that beginners (and even some veterans) make. It is an extremely frustrating error because everything else in your program may be correct but a simple %d instead of %f will make it appear like you have major errors in your program. Then you may spend a lot of time looking at your logic, doing hand calculations and in the end it is a simple conversion specification that has caused the problem. If you get total nonsense or zeros for your output, check your conversion specifications before you investigate other, more difficult to trace, sources of error.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment