if we print a float using %d garbage value is printed....but if we scan a float value using %d & int...the value gets truncated...What is the reason behind it...
manishanibhwani
0
Newbie Poster
Recommended Answers
Jump to Postfloat is 8 bytes and int 4 bytes if you say %f you expect 8 bytes and type float
#include <stdio.h> int main() { int iInt = 1; printf("int %d float %f",iInt, (float)iInt); return 0; }
btw i suggest you read char buffer in and then …
Jump to PostWhat is the reason behind it...
If you lie to printf(), you get what you deserve. When you tell printf() to expect an int, it treats whatever you pass like an int. When you tell printf() to expect a float, it treats whatever you pass like a float. …
All 6 Replies
Sokurenko
42
Junior Poster
I_m_rude
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
manishanibhwani
0
Newbie Poster
Sokurenko
42
Junior Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.