Below is the small program
Displays OutPut as = -0.028148Code:#include<stdio.h> #include<stdlib.h> int main() { printf(" %#f\n", 415); return 0; }
Unable to understand, please help.....
I am using NetBeans 6 under Ubuntu.
This is a discussion on Unusual program Output, Help within the C Programming forums, part of the General Programming Boards category; Below is the small program Code: #include<stdio.h> #include<stdlib.h> int main() { printf(" %#f\n", 415); return 0; } Displays OutPut as ...
Below is the small program
Displays OutPut as = -0.028148Code:#include<stdio.h> #include<stdlib.h> int main() { printf(" %#f\n", 415); return 0; }
Unable to understand, please help.....
I am using NetBeans 6 under Ubuntu.
with each run, it displays a random number
Where you supply 415 - that's supposed to be a reference to a float variable.
Mac and Windows cross platform programmer. Ruby lover.
Quote of the Day
12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.
Amen brother!
You're telling it to print a double, but you're not passing it a double.
Use 415.0 instead.
Welcome to the complete lack of type safety in printf!
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
you put 4 bytes on stack, but using format f - which reads 8 bytes and interprets them as double... So you get 4 random bytes of garbage in your output.
Make your number to be consistent with the format, for example 415.0
If I have eight hours for cutting wood, I spend six sharpening my axe.
Mac and Windows cross platform programmer. Ruby lover.
Quote of the Day
12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.
Amen brother!
thanks guys,