Are one-dimensional arrays and two-dimensional arrays different individuals with the same array? ?

  c++, question

One-dimensional array

int a[2] = {1 , 2};
 int* p_a = a;
 
 int i = 0;
 
 for (;   i < 2;  ++i)
 {
 printf("*(p_a + %d) = %d \n" , i , *(p_a + i));
 }

Output:

clipboard.png

Two-dimensional array

int a[2][2] = {
 {1 , 2}
 };
 
 int* p_a = a;
 
 int i = 0;
 int j = 0;
 
 for (;   i < 2;  ++i)
 {
 for (j = 0;   j < 2;  ++j)
 {
 printf("(*p_a)[%d][%d] = %d\n" , i , j , (*p_a)[i][j]);
 }
 }

Compilation error:

clipboard.png

here(*p_a)It should all point to a one-dimensional array. Why is there an error when it comes to a two-dimensional array? It looks like a two-dimensional array is a whole. What is the reason? ?

*p_aThe type of is int. otherwise, it is UB. read the posthttps://stackoverflow.com/que …