![]() |
confusion with format string
main()
{ float x=1.0; int y=3; printf("x=%d",x); printf("\ny=%f",y); } output: x=0 y=285737.000011(why this unexpected output?) :confused: though x is floating type variable,when it is displayed in int farmat why it's output is x=0 on the other hand value of y is something annoying |
Re: confusion with format string
You used the wrong format for the printf commands.
Code:
$ gcc -W -Wall -ansi -pedantic -O2 foo.c |
Re: confusion with format string
%d and %f are for integer and float respectively.
|
Re: confusion with format string
Quote:
|
Re: confusion with format string
> but can u tell why we get such an output.
Because your code is broken. Broken code produces whatever it feels like, regardless of what you might expect / like / desire / hope for. Use a compiler which can check your printf / scanf format strings (like I posted), and don't run any code which has warnings in it. |
Re: confusion with format string
When you will go definition of printf. A sample of it..
Code:
int printf( . . . ) |
| All times are GMT +5.5. The time now is 20:52. |