Lets say I have the following variables:
char c[] = "ABC";
char *ptr = &c;
char **ptr2 = &ptr;
I know I can iterate over a pointer to an array of char, this way:
int i;
for(i=0; i<3; i++){
printf("TEST******************, %c\n", ptr[i]);
}
How do I iterate over a pointer to a pointer?
If I did not misunderstand your question, this code should make a job
Suppose:
In this scenario:
ptr
represents an address ofc
ptr2
represents an address ofptr
. A pointer to a pointerptr3
is a value stored inptr
, which is an address ofc
.**ptr3=&ptr
means - Take address ofptr
, look inside and assign its value (not address) toptr3
If I understood your question correctly, you need to use pointers to pointers:
ptr2
in my example instead ofptr3
If so, you can access elements like :
For the record the following will yeld the same results. Try it.
Good discussion for your reference is here
For your example:
let me give an example,
or one more best example which you can understand. here i have used 2 for loops because i am iterating over each character of the array of strings.