What is the type of element of a 2d array in c and c ++?

eg.

int arr[2][3] = ...

Type arr[0]-

int (*)[3] // pointer to int[3], which is a pointer. 

or

int[3] // an array whose size is 3, which is an array. 

Google says nothing about the question.

I know that a pointer and an array are different types (derived types).

Perhaps C and C ++ treat it differently, I hope to see the standard wording.

+4
source share
1 answer

arr[0]has a type int [3]that is not a pointer.

int (*p)[3]has a type int(*)[3]indicating a pointer to an array of 3 elements.

The pointer is not an array, and array is not a pointer.

, 2d- ( , ), , int (*)[3].

C 2d - , .

  • arr - , 3.

  • arr[0] ( sizeof ..) , int*.

  • arr[0][0] int.

  • &arr[0].. , ? int(*)[3].

+15

Source: https://habr.com/ru/post/1691559/


All Articles