we are basically assigning address value "a" to a char pointer p..(the reason y char pointer is used u will get to know it at the end)
we know p[b] means *(p+b)....then &p[b] means &*(p+b) i.e. p+b i.e a+b we used char pointer to increment it one by one..had we used int pointer.. it wud have incremented it +4*b..... there is another way of doing it.... *printf("%d\n",printf("%*c%*c",a,"",b,"")); * On Wed, Jul 13, 2011 at 1:52 PM, nicks <crazy.logic.k...@gmail.com> wrote: > if someone has better idea...then please suggest that..... > > plz explain how this is calculating sum -->> sum= (int)&p[b]; > > > On Wed, Jul 13, 2011 at 1:50 PM, nicks <crazy.logic.k...@gmail.com> wrote: > >> I am looking for a code which can add without using + sign >> >> i searched the net and found the following code......can anyone explain me >> whats happening in this ?? >> >> #include<stdio.h> >> #include<conio.h> >> int main() >> { >> int a=3000,b=20,sum; >> char *p; >> p=(char *)a; >> sum= (int)&p[b]; //adding a & b >> printf("Answer is :"); >> printf("%d",sum); >> return 0; >> } >> >> > -- > 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. > -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * <https://www.facebook.com/profile.php?id=100000655377926> "NEVER SAY NEVER" * -- 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.