gpt4 book ai didi

c - 是一个==*一个??关于指针的查询

转载 作者:太空狗 更新时间:2023-10-29 15:50:33 25 4
gpt4 key购买 nike

int main()
{
int a[4][3] = {10,20,30,40,50,60,70,80,90,100,110,120};
printf("%d",((a==*a) && (*a==a[0])));
return 0;
}

在控制台上打印 1。谁有合乎逻辑的解释??

最佳答案

数组在表达式中使用时会转换为指针,除非它们是 sizeof 和一元 & 运算符的操作数。 a*a 是不同的类型(衰减后)但具有相同的地址值。

  • a decays to pointer to first element (first row) of array and is of type int (*)[3].
  • *a dereference the row pointed by a and further decayed to pointer to first element of first row. It is of type int *.
  • a[0] is representing the first row which is of type int [3]. In expression it decays to pointer to first element of first row and is of type int * after decay.

数组的地址是第一个字节的地址,因此数组的地址第一行的地址第一个元素的地址 都具有相同的值。因此,在衰减之后,所有的 a*aa[0] 都指向相同的位置。

这是上述解释的图形 View :

Stack Overflow What exactly is the array name in c?

关于c - 是一个==*一个??关于指针的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24697795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com