让我们以以下示例为例,交换a和b的值。
void swap(int* a, int* b) {
// remember, a and be are both memory addresses now!
printf("The address of a is: %p\n", a);
printf("The address of address-of a is: %p\n", &a);
int tmp = *a;
*a=*b;
*b=tmp;
}
打印输出给我:
a的地址为:0x7ffd36e62d08
a的地址的地址为:0x7ffd36e62cd8
第二个printf
语句具体告诉我们什么?例如:
int a = 4;
&a; // address-of a
int* b; = &a;
b; // address-of a
*b; // value-of a
&b; // address-of ...?
那只是在堆栈上的内存地址位置吗?