you are just changing the pointers . so second ptr will point to third string and third will point to second string
On Wed, Sep 7, 2011 at 11:34 AM, Shachindra A C <sachindr...@gmail.com>wrote: > I assume you expect to see the strings interchanged. But you are not > changing anything in the memory. So in main(), pstr[0] and pstr[1] contains > whatever was there earlier. If you change the parameters of the swap to > swap(char **,char **), pass the addresses of pstr[0] ,pstr[1] and then do > whatever u r doing in swap, the strings will get exchanged. > > On Wed, Sep 7, 2011 at 11:26 AM, piyush agarwal <pshagl...@gmail.com>wrote: > >> #include<stdio.h>void swap(char *, char *); >> int main() >> { >> char *pstr[2] = {"Hello", "piyush"}; >> swap(pstr[0], pstr[1]); >> printf("%s\n%s", pstr[0], pstr[1]); >> return 0; >> }void swap(char *t1, char *t2) >> { >> char *t; >> t=t1; >> t1=t2; >> t2=t; >> } >> >> >> >> -- >> Piyush Agarwal >> Final Year Undergraduate >> Department of Computer Engineering >> Malaviya National Institute of Technology >> Jaipur >> -- >> 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. >> > > > > -- > Regards, > Shachindra A C > > -- > 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.