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 
The reason is that int f( int P[2][4] ); is a synonym for int f( int (*P)[4] ); The first dimension in a function declaration is just comments.
The reason is that function parameters never really have array type. The compiler treats the declaration
int f(int P[2][4]);
as though it really said
int f(int (*P)[4]);
P is a pointer to an array of four ints.  The type int [3][4] decays to that same type.  But the type int [2][3] decays to the type int (*)[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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With