read how the floating numbers are stored in memory it will help....
i understood the most except this ---
float p=4.5;
printf("\n%f,%d",p,p);
*output -
*4.500000,0
and if we use
printf("\n%d,%f",p,p);
*output -
*0,0.00000
i want to know why just changing the order of %d and %f is changing the
output..........plz help !!
On Sat, Jun 4, 2011 at 12:13 PM, Anika Jain <[email protected]> wrote:
> read ch1 in understanding pointers in c by kanetkar.. it says tht if u use
> %d format specifier to print a float an unknown value will come.. and if use
> %f to print an integer then also unknown value will come.. so u r not
> supposed to switch format specifiers like this
>
>
> On Sun, Jun 5, 2011 at 12:33 AM, Rohit Sindhu <
> [email protected]> wrote:
>
>> Your format specifiers in the printf statements are not right.
>> Also integers and floats are stored differently internally. Also, you have
>> to explicitly cast float into int as automatic conversion is not applicable
>> here in printf.
>>
>> I hope this code helps your cause ,
>>
>> #include<stdio.h>
>>
>> int main()
>> {
>> float a[]={13.24,1.5,1.5,5.4,3.5};
>> float *j;
>> j=a;
>> j=j+4;
>> printf("\n%p,%f,%f",j,*j,a[4]);
>>
>> float p=3.5;
>> printf("\n%f,%d",p,(int)p);
>>
>> p=4.5;
>> printf("\n%d,%f",(int)p,p);
>>
>>
>> }
>>
>>
>>
>>
>>
>>
>> On Sat, Jun 4, 2011 at 2:21 PM, himanshi narang <
>> [email protected]> wrote:
>>
>>> #include<stdio.h>
>>>
>>> int main()
>>> {
>>> float a[]={13.24,1.5,1.5,5.4,3.5};
>>> float *j;
>>> j=a;
>>> j=j+4;
>>> printf("\n%d,%d,%d",j,*j,a[4]);
>>>
>>> float p=3.5;
>>> printf("\n%f,%d",p,p);
>>>
>>> p=4.5;
>>> printf("\n%d,%f",p,p);
>>>
>>> }
>>>
>>>
>>> output----
>>> -1080027596,0,1074528256
>>> 3.500000,0
>>> 0,0.000000
>>>
>>> plzz explain y i m getting dis output......
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Rohit Sindhu
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.