string swapping works well with char ** but not with char *
c, function, pointers, string, swap
Solution
I assume you understand that to swap integers you would have function like `swap(int *, int *)`
Similarly, When you want to swap strings which is `char *`. You would need function like `swap(char **, char **)`.
In such cases, you take their pointers and swap their content (otherwise values will not be swapped once function returns). For integer content, pointer is `int *` and in case of strings content is `char *` pointer to it is `char **`.
Problem
In this program I have swapped the first 2 names ``` #include<stdio.h> void swap(char **,char **); main() { char *name[4]={"amol", "robin", "shanu" }; swap(&name[0],&name[2]); printf("%s %s",name[0],name[2]); } void swap(char **x,char **y) { char *temp; temp=*x; *x=*y; *y=temp; } ``` This programs runs perfectly but when I use the `function swap(char *,char *)` it does not swap the address why? why I have to use pointer to pointer?