Hi,
I am trying to get a better understanding of pointers and pointers to pointers.
I get that int a; is a variable that has a value that is an integer, and that int *b; is a variable that is a pointer to something that has a value that is an int, and that int **c is a pointer to a pointer to something that has a value that is an int.
The code I was testing with (see below) seems to indicate that I can keep adding an * to increase the ... Umm ... "depth?" of how far I am pointing.
Code:
#include <stdio.h>
int main(int argc, char *argv[]) {
int a;
int *b;
int **c;
int ***d;
int ****e;
b=&a;
c=&b;
d=&c;
e=&d;
a=20;
printf("\na=%d\n",a);
printf("\n*b=%d\n",*b);
printf("\n**c=%d\n",**c);
printf("\n***d=%d\n",***d);
printf("\n****e=%d\n",****e);
return 0;
}
This seems to mean that any function I create needs to KNOW the exact "depth?" of a given variable passed by reference. Is that true? Do I really need to do something like this:
Code:
int somefunc(int **********varname){
/* some code */
}
Or is there some syntax that can be used that says something like: this variable is a pointer to pointers that eventually leads to a block of memory that contains an int.
I understand that what I am asking maybe completely stupid and pointless (pun not intended but recognized) and I don't know that I would ever need or want something like this, but I want to understand it all better.
Thanks for any input.