Can I cast an an array of arrays int arr[4][10]
to an array of pointers int *arr[4]
?
How should I write the cast?
Can I cast an an array of arrays int arr[4][10] to an array of pointers int *arr[4]?
No.
You can cast int arr[4][10]
to int (*arr)[10]
though — or rather the former is implicitly convertible to the latter that you don't require any explicit cast at all.
BTW, it is better if you avoid using raw arrays to begin with. Prefer std::array<T,N>
instead.
In this case, you could use std::array<std::array<int,10>,4>
.. and then try designing your code in such a way which doesn't require casting at all.
note that "int* a[4]" has only 4 pointer to int,Otherwise it can indicate 4 int array,but int "a[4][10]" has 40 integer data type.
so you can not cast it.