指针是一种特殊类型的变量,用于存储值的地址,因此,指针名表示的是地址。*运算符被成为间接值或解除引用运算符,将其应用于指针,可以得到该地址存储的值。
对指针的理解可以参照以下的例子:
#includeusing namespace std;int main() { int updates = 6; int *p_updates; p_updates = &updates; cout << "Values: updates = " << updates; cout << ", *p_update = " << *p_updates << endl; cout << "Address: &updates = " << &updates; cout << ", p_update = " << p_updates << endl; *p_updates = *p_updates + 1; cout << "Now updates = " << updates << endl; return 0;}
下面是该程序的输出:
Values: updates = 6, *p_update = 6Address: &updates = 0x7fffd9c0e424, p_update = 0x7fffd9c0e424Now updates = 7
(未完待续~~有新的回顾想法和思路后继续补充~~)