I read in a book that, int f (int P[2][4]) cannot accept A[2][3], but B[3][4] is fine. what is the reason for this?
Especially when we create dynamic allocation using pointers, this should not be a problem.
Thanks
I read in a book that, int f (int P[2][4]) cannot accept A[2][3] ,
Share
The reason is that function parameters never really have array type. The compiler treats the declaration
as though it really said
Pis a pointer to an array of fourints. The typeint [3][4]decays to that same type. But the typeint [2][3]decays to the typeint (*)[3]instead, which is not compatible.Dynamic allocation is another matter entirely, and it probably does not involve array-of-array types no matter how you do it. (Array of pointers, more likely.)