Arrays 指向2D数组声明的指针有问题

Arrays 指向2D数组声明的指针有问题,arrays,pointers,Arrays,Pointers,我对指向2D数组声明的指针有一些问题 我在下面写了一些代码: typedef int ptr2di[3][3]; void main() { int a[3][3] = { { 1, 2, 3 }, { 4, 5, 6 } }; ptr2di *ptr=&a; //ptr2di *ptr=a; cout << a << endl << &a; } 结论:a=&a=数组的基址。 然后我在ptr2di声明中做了一点更改: //ptr2di *

我对指向2D数组声明的指针有一些问题

我在下面写了一些代码:

typedef int ptr2di[3][3];
void main()
{
int a[3][3] = { { 1, 2, 3 }, { 4, 5, 6 } };

ptr2di *ptr=&a;
//ptr2di *ptr=a;

cout << a << endl << &a;
}
结论:a=&a=数组的基址。 然后我在
ptr2di
声明中做了一点更改:

//ptr2di *ptr=&a;
ptr2di *ptr=a;
它有一个错误C2440:“初始化”:不能从“int[3][3]”转换为“ptr2di(*)”

所以,这就是我的问题,我不明白
a
&a
之间的区别是什么?
大家能帮我解释一下吗?

我猜a的值实际上是0029F940(因为它是一个数组),cout只是查看值,但编译器将a视为数组int[3][3],并且不允许将其赋值给ptr2di*,因为它需要指向int[3][3]的指针。因此,a和&a的值相同,但类型不同,编译器正在检查类型是否合法赋值

类似的例子:

int a = 1;
// Valid: Assigning the address of a (which is an int) to a pointer to an int
int *ptr = &a;

// Invalid: Assigning an the int a to a pointer to an int
int *ptr = a;
如果你这样做会发生什么? 库特
int a = 1;
// Valid: Assigning the address of a (which is an int) to a pointer to an int
int *ptr = &a;

// Invalid: Assigning an the int a to a pointer to an int
int *ptr = a;