1

I don't quite understand where the error is here:

int *parr[22];  // Array of int* pointers
parr[0] = ptr1;
parr[1] = ptr2;
//... 

int *(*pparr)[22]; // A pointer to a int* array[22]
pparr = parr; // ERROR

the error tells me error C2440: '=' : cannot convert from 'int *[22]' to 'int *(*)[22]'

how come that the types are not equal? The name of the array should be equal to a reference to the first element of the array, something like

parr => &parr[0]

so the line seems right to me

2
  • 1
    You want stackoverflow.com/a/6130884/315052 Commented Nov 10, 2012 at 13:17
  • Must be pparr = &parr; for the types to be compatible. Commented Nov 10, 2012 at 13:17

3 Answers 3

1

As pparr is A pointer to a int* array[22] so you need to write

pparr = &parr;

You need to store address in the pointer and not the pointer itself.

It is same like when you have

int a=3;
int *b;
b=&a;

You are storing address of a in b, similarly you need to store address of parr in pparr

EDIT: To clarify OP's comment

You can't assign the address of the first element, but the address of the pointer that is pointing to first element.(therefore pparr = &parr;)

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

2 Comments

Yes but the name of the array should be equal to a reference to the first element of the array, so I should already have the address
ya thats why we are not writing pparr = &parr[0] we are writing pparr=&parr
1

An int*[22] can decay to an int**, but you cannot assign an int** to an int*(*)[22].

Comments

0
int *(*pparr)[22];  //This one is an array of function-pointers returning an int pointer. 

int **pptr;  //Points to an array of pointer

So you can write

pptr = parr;

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.