C中的编译器如何获得数组第一个元素的地址与整个数组地址之间的差异?

How can the compiler in C get the difference between the address of the first element of the array and the address of the whole array?

鉴于这个问题,我完全了解以下事实:

1) 数组名是指向数组第一个元素的固定指针

2) 二维矩阵的名称是它的第一个一维数组的地址。

3)以及x[i]和&x[i]在算术运算中的区别(i为非负整数)

编译器是MinGW C 中的编译器如何获得数组第一个元素的地址与整个数组的地址之间的差异,尽管它们具有相同的数值?

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main(void)
{
    int x[3][3] = {1,2,3,4,5,6,7,8,9} ; 
    int *p  ; 
    for(p = &x[0] ; p < &x[0] + 1 ; p++) //Warning: comparison of distinct pointer types in this line of code 
        printf("%d\n",*p) ; 

    return 0 ; 
}

您正在分配/比较两种不同的指针类型。

x 的类型为 int [3][3],即 int 的大小为 3 的数组的大小为 3 的数组。从那里开始,x[0] 的类型为 int [3],即 int 的大小为 3 的数组。

随后,&x[0] 的类型为 int (*)[3],即指向 int 大小为 3 的数组的指针。相反,p 的类型为 int *,即指向 int 的指针。这些是不同的类型,这就是编译器向您发出警告的原因。

编译器或多或少以我描述的方式解析表达式,查看对象的类型并查看结果表达式的类型如何随着每个运算符的应用而变化。