I have the following example code:
void doAlloc(int **p) {
*p = (int *)malloc(sizeof(int));
**p = 80;
}
int main() {
int *ptr2;
doAlloc(&ptr2);
printf("%d\n", *ptr2);
free(ptr2);
}
If I understand correctly, ptr2 is a pointer variable, and &ptr2 is "address of" that pointer variable in memory.
My question is, since doAlloc accepts a double pointer int **p as parameter; I don't understand why &ptr is a int **.
I would expect something like this to be done instead:
int **ptr2;
doAlloc(ptr2);
How is the "address of" ptr2 considered to be a valid value to pass as a double pointer?
Any help is greatly appreciated! Thanks.