简体   繁体   English

C语言:两种指针分配方式之间的区别

[英]C language: Difference between two ways of pointer assignment

int a[10];
int *p = a; //way 1
int *p1 = &a[0]; //way 2

Could you tell me the differences between two ways above? 您能告诉我以上两种方式之间的区别吗?

There is no difference. 没有区别。 Both assign the address of the first element to the pointer p and p1 respectively. 两者都将第一个元素的地址分别分配给指针pp1

In the first case, a is automatically converted to the address of the first element. 在第一种情况下, a将自动转换为第一个元素的地址。 In the second case it uses the address of the first element explicitly. 在第二种情况下,它显式使用第一个元素的地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM