Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
说,我定义了一个数组:
int a[5];
和
a = &a[0];
是数组开头的地址。
我的问题是,是否a像指针变量一样存储在内存中的某个地方?如果是这样,当我尝试打印a( &a) 的地址时,为什么会得到与 相同的值a?
a
&a
当你声明一个数组时,唯一留出的存储空间是数组元素本身;没有为指向第一个元素的指针预留存储空间。
当编译器看到一个数组表达式不是sizeofor&运算符的操作数,或者不是用于在声明中初始化另一个数组的字符串文字时,它会将该数组表达式转换为指针表达式,并且指针表达式将是数组中第一个元素的地址。
sizeof
&