当您尝试切换指针时,“=”是什么意思。
例如:current->next = previous
和current = previous
。
让我们来做第二个作业,current = previous
。在这里,小方框是指针本身的值,而右边的矩形是它们所指向的东西。
分配前:
+---+ +-----------+
current | --|--------> | Obj1 |
+---+ +-----------+
+---+ +-----------+
previous | --|--------> | Obj2 |
+---+ +-----------+
赋值后,两者都current
指向previous
对象Obj2。
+---+ +-----------+
current | --|--+ | Obj1 |
+---+ | +-----------+
|
+---+ +-----> +-----------+
previous | --|--------> | Obj2 |
+---+ +-----------+
重要要点:
current
没有改变。它不会因分配而“删除”或破坏。Obj1
也不Obj2
修改它们自己。*current = func()
访问(读取)它时,将反映其更改的状态。 current
previous