actually when you subtract two pointers ... its get divided by the size of the variable type its point two... for example.. if you do .. p+1... where let say p is 200 and points to an int type variable then p+1 is 202...(assuming int is of size 2) so (p+1)-p..i.e 202-200 is 1 and not 2
On Sun, Jun 13, 2010 at 1:46 PM, divya jain <sweetdivya....@gmail.com>wrote: > bt the ans that sharad gave is ryt.. > acc to me 1st row n 1st col of o/p shd b 2 (if size of int is 2) bt it is > 1... > > > On 13 June 2010 12:10, Rohit Saraf <rohit.kumar.sa...@gmail.com> wrote: > >> @divya: u r rite.. that * should not be there >> >> -------------------------------------------------- >> Rohit Saraf >> Second Year Undergraduate, >> Dept. of Computer Science and Engineering >> IIT Bombay >> http://www.cse.iitb.ac.in/~rohitfeb14<http://www.cse.iitb.ac.in/%7Erohitfeb14> >> >> >> On Sun, Jun 13, 2010 at 11:07 AM, divya jain <sweetdivya....@gmail.com>wrote: >> >>> ptr is a pointer naaa...then why ptr-p=*(&(arr+1)-&arr) ??? >>> why not &(arr+1)-&arr ?? >>> i knw m wrong somewhr...plz correct me >>> >>> >>> On 13 June 2010 07:57, Mahesh_JNU <mahesh.jnumc...@gmail.com> wrote: >>> >>>> agreed ......... >>>> >>>> >>>> On Sun, Jun 13, 2010 at 7:48 AM, sharad kumar >>>> <aryansmit3...@gmail.com>wrote: >>>> >>>>> 111 >>>>> 222 >>>>> 333 >>>>> 344 >>>>> ptr++ ->u do posst increment >>>>> hence it goes to 1 >>>>> ptr-p=*(&(arr+1)-&arr)=1 >>>>> llrly for other cases >>>>> when u do *ptr++ due to operator precedence ptr++ is done and then >>>>> dereferenced. >>>>> hence u get 222 >>>>> next *++ptr >>>>> the ptr is incremented after dereferencing hence u get 333 >>>>> next ++*ptr here the value t ptr s incrementas it is treated as++(*ptr) >>>>> hence u get 3 but others refer to location hence 44 >>>>> >>>>> >>>>> On Sat, Jun 12, 2010 at 9:21 PM, divya <sweetdivya....@gmail.com>wrote: >>>>> >>>>>> #include<stdio.h> >>>>>> int main() >>>>>> { >>>>>> static int arr[]={0,1,2,3,4}; >>>>>> int *p[]={arr,arr+1,arr+2,arr+3,arr+4}; >>>>>> int **ptr=p; >>>>>> ptr++; >>>>>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr); >>>>>> *ptr++; >>>>>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr); >>>>>> *++ptr; >>>>>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr); >>>>>> ++*ptr; >>>>>> printf("%d %d %d\n",ptr-p,*ptr-arr,**ptr); >>>>>> return 0; >>>>>> } >>>>>> wat shd b the o/p n why... >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "Algorithm Geeks" group. >>>>>> To post to this group, send email to algoge...@googlegroups.com. >>>>>> To unsubscribe from this group, send email to >>>>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >>>>>> . >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> yezhu malai vaasa venkataramana Govinda Govinda >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Algorithm Geeks" group. >>>>> To post to this group, send email to algoge...@googlegroups.com. >>>>> To unsubscribe from this group, send email to >>>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >>>>> . >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>> >>>> >>>> >>>> >>>> -- >>>> Mahesh Giri >>>> MCA Final Sem >>>> JNU, New Delhi >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to algoge...@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@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.