this is very dark corner in C , propably the most mis-understood subjects, pointers-array and
pointers to pointers . I learn by myself and trying to get ahold of this subject
is really hard.
I'll post a few questions , thanks in advanced for the repliers!
arrays of pointers:
how can you excees elements in multi dimentional -pointer-arrays?
for example , let us consider this pointer-array:
Code:
char *ptr[]={
{"john","marr","dennis"},
{"cat","dog","rat"},
{"mom","dad","brother"}
}
how can we, for example, print out "dog" using pointers?
and in this version?
Code:
char *ptr1[]={"john","marr","dennis"};
char *ptr2[]={"cat","dog","rat"};
char *ptr3[]={"mom","dad","brother"};
char *ptr[]={
*ptr1,*ptr2,*ptr3
};
pointers to pointer:
1) what is the use of pointers to pointers? why would we make another pointer to pointer?
what gain do we have from it ?
2) one site I looked at gives the following example for function that swaps strings.
Code:
void swap_strings(char** str1, char** str2) {
char* temp = *str1;
*str1 = *str2;
*str2 = temp;
}
the site indicates that this kind of function has to get pointer to pointer - why?
strelen/strcpy etc. only use regular pointers..
also , why does the temp in the end is not with * ?