这是一个关于指针的基本 C 程序:
#include <stdio.h>
int main() {
int variable = 20;
int *pointerToVariable;
pointerToVariable = &variable;
printf("Address of variable: %x\n", &variable);
printf("Address of variable: %x\n", pointerToVariable);
printf("Address of variable: %x\n", *pointerToVariable); // * is the DEREFERENCING OPERATOR/INDIRECTION OPERATOR in C.
//It gives the value stored at the memory address
//stored in the variable which is its operand.
getchar();
return 0;
}
这会产生以下输出:
Address of variable: 8ffbe4
Address of variable: 8ffbe4
Address of variable: 14
但是*pointerToVariable
应该打印 20,不是吗?因为*
给出了存储在其操作数中存储的内存地址的实际值,对吧?我错过了什么?