2

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.

1
  • You might have to include a code example and show what exactly that didn't work. (int* (*)[] is a pointer to incomplete array type, so that can be an issue in some contexts. Commented Nov 8, 2021 at 10:19

2 Answers 2

2

You can simply do p = &arr.

Try here.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.