我正在涉足 c 指针,但无法解释以下代码:
int main()
{
int i = -3;
int *ptr;
int **ptr2;
int ***ptr3;
ptr = &i;
ptr2 = &ptr;
ptr3 = &ptr2;
printf("ptr = %p\n",(void *)ptr);
printf("&ptr = %p\n",(void *)&ptr);
printAddr(&ptr);
printAddr2(&ptr2);
printAddr3(&ptr3);
return 0;
}
void printAddr(int **num)
{
printf("address of int ** = %p\n", (void *)&num);
}
void printAddr2(int ***num)
{
printf("address of int *** = %p\n", (void *)&num);
}
void printAddr3(int ****num)
{
printf("address of int **** = %p\n", (void *)&num);
}
输出如下:
ptr = 0xbf9d64a0
&ptr = 0xbf9d64a4
address of int ** = 0xbf9d6490
address of int *** = 0xbf9d6490
address of int **** = 0xbf9d6490
我的疑问是为什么要解决(address(int)) == address(address(address(int)))
?
非常感谢您的澄清。
我发现这个问题是相关的:
但是作者明确指定它们是平等的。