Comments (7)
@zzw1123 因为这个函数可能修改头指针(将头指针赋空值)。在C语言中函数传参本质上是传值,即拷贝实参。所以要修改实参只能传递实参的地址,利用指针的间接性进行修改。而此处实参是一个指针,所以要修改指针,就要传递该指针的地址,于是就是两个星号啦:)
from codinginterviewchinese2.
想问下,函数形参里边ListNode** pListHead这里,为什么要用两个星号呢?
一个星号表示头指针不就可以了吗?
对链表还是理解的不太到位,请指正~
from codinginterviewchinese2.
@bodu93 明白啦~~谢谢!
from codinginterviewchinese2.
@zzw1123 因为这个函数返回值是void所以必须改掉头结点本身的结构,所以不是一个的值传递。如果有返回值的话可以用一个。
另外ListNode** head可以写成ListNode*& head。
from codinginterviewchinese2.
@bodu93 请问为什么 delete了 pToBeDeleted还要让pToBeDeleted 指向 nullptr,del了还不可以?
from codinginterviewchinese2.
@WeifaGan你可以定义一个new一个字符串,delete他的指针,但是可以还是可以(有时)cout这个字符串的。delete只是表示这个内存可以被其他人用,但是内容要等下次写入时覆盖,不会立即删除。设置为nullptr可以防止误用(cout delete的指针是未定义行为)
from codinginterviewchinese2.
@woshigerunze 原来如此!谢谢解答!
from codinginterviewchinese2.
Related Issues (20)
- 面试题60 第二种解法是不是有问题啊,会int溢出
- Partition function has extremely bad performance for array with identical values
- 面试题14剪绳子动态规划 HOT 5
- 面试题三2 题解有问题 HOT 4
- #面试题37
- 面试题30 是否有必要总是将min(value, m_min.top())压入辅助栈中? HOT 1
- 面试68题答案错误
- 面试题17的本题扩展
- c
- 面试题54:二叉搜索树的第K大节点 HOT 1
- 第二版勘误
- Singleton
- 面试题19的题目有误? HOT 1
- 面试题3 题目二部分测试用例过不了 HOT 3
- pro
- 面试题10:斐波那契数列测试用例过不去 HOT 1
- 51题,数组中的逆序对
- List.cpp 头文件 #include "list.h" 有误
- How to build and run CommonParentInTree.cpp on macOS?
- Hu
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codinginterviewchinese2.