我是C新手,我需要通过下面的代码来理解屏幕上打印的每个值的含义:
#include<stdio.h>
int main()
{
int x = 10;
int *ptr = &x;
printf("%d %d %d\n", *ptr,**&ptr, 2**ptr);
return 0;
}
输出(海合会):
10 10 20
在这里,我声明了变量x
和ptr
指向x
变量。因此,*ptr
打印了 x
的值。但是我看不懂**&ptr
和2**ptr
的值。
提前致谢。
最佳答案
这里,*
和&
操作符相继使用时相互抵消。
**&ptr
与*ptr
相同,这里,ptr
保存x
变量的地址.因此,在此处打印 x
的值。
2**ptr
被解释为 2 * (*ptr)
。所以,2 * (10)
等于 20
。
关于c - C指针的 "**&ptr"和 "2**ptr"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46987575/