2006/3/13, ajay mall <[EMAIL PROTECTED]>:
> Hi,
>
> Can u tell what would be output of following code and what is  reson behind
> this?
>
> void main()
> {
>    float a=4;
>    int i=2;
>   printf("%f..........%d",i/a,i/a);
first, printf is very stupid. so does any function who use the
variable argument list. the reason is that they do not know what's the
type of its real arguments.

for this example, the format string is "%f...%d",
so, *printf* this his arguments to be one *double* and then one *int*. why?

if u read the C standard, u should note that the type conversion rule
applied here is:
convert real arguments with type *float*,*double* into double
convert real arguments with type *char*,*short*,*int* into int

so the real arguments printf receive is two doubles with value 0.5 and 0.5

but what he want is one double and then one integer? what will happened?

the compiler will push two double (8 bytes in X86 arch.. each) into
the stack. then printf will pop out a double (this is right), and then
an integer( he will simply extract the first 4  bytes of the second
double to be this integer). so what is the value of this integer ? it
depends on which arch.. u r on! also depends how ur machine express an
integer and a double.

maybe this will help u. if any problem, plz let me know!
>   printf("%d..........%f",i/a,i/a);
> }
>
> --
> " Talent hits a target no one else can hit
>      Genius hits a target no one else can see ."
>
> FROM- AJAY BAHADUR MALL
> #N-405,DSK BLOCK,MMM HALL,
> IIT KHARAGPUR(WEST BENGAL)-721302
> Mail-id:[EMAIL PROTECTED]
> MOBILE NO: +919932978592
>
>


--
myblog: http://gnor.net/daizisheng/blog/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to