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 < rohit.sindhu.spec...@gmail.com> 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 < > himanshinarang...@gmail.com> 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 algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> 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 algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.