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

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
Johnny Pauling
  • 12,701
  • 18
  • 65
  • 108

3 Answers3

1

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

fredoverflow
  • 256,549
  • 94
  • 388
  • 662
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;)

Ankur
  • 12,676
  • 7
  • 37
  • 67
  • 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 – Johnny Pauling Nov 10 '12 at 13:27
  • ya thats why we are not writing `pparr = &parr[0]` we are writing `pparr=&parr` – Ankur Nov 10 '12 at 13:57
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;
pbhd
  • 4,384
  • 1
  • 20
  • 26