I have an array of int pointers
int * arr[3];
If I want to define a pointer to arr
, I can do the following:
int * (*p)[] = &arr;
However, in my code, I need to first declare that pointer:
int *(*p)[];
My question is, how to assign &arr
to it after it has been declared. I have tried (*p)[] = &arr;
but that didn't work.
CodePudding user response:
You can simply do p = &arr
.
Try here.
CodePudding user response:
If you want to assign p to arr you simply have to do p = &arr; this is because when you write p you basically are saying to C: this is the pointer to a array of pointers
So when you &arr you get the same type as & gives you the pointer to the variable next to it
Also beware that if you want the value of a variable inside a struct that its pointed to( ie struct something *a, where inside there int i) you put a -> (making it a a->integer;)
You should update the answer to the full extent