Giter Club home page Giter Club logo

Comments (7)

bodu93 avatar bodu93 commented on June 5, 2024 3

@zzw1123 因为这个函数可能修改头指针(将头指针赋空值)。在C语言中函数传参本质上是传值,即拷贝实参。所以要修改实参只能传递实参的地址,利用指针的间接性进行修改。而此处实参是一个指针,所以要修改指针,就要传递该指针的地址,于是就是两个星号啦:)

from codinginterviewchinese2.

zzw1123 avatar zzw1123 commented on June 5, 2024

想问下,函数形参里边ListNode** pListHead这里,为什么要用两个星号呢?
一个星号表示头指针不就可以了吗?
对链表还是理解的不太到位,请指正~

from codinginterviewchinese2.

zzw1123 avatar zzw1123 commented on June 5, 2024

@bodu93 明白啦~~谢谢!

from codinginterviewchinese2.

woshigerunze avatar woshigerunze commented on June 5, 2024

@zzw1123 因为这个函数返回值是void所以必须改掉头结点本身的结构,所以不是一个的值传递。如果有返回值的话可以用一个
另外ListNode** head可以写成ListNode*& head。

from codinginterviewchinese2.

forwardwfg avatar forwardwfg commented on June 5, 2024

@bodu93 请问为什么 delete了 pToBeDeleted还要让pToBeDeleted 指向 nullptr,del了还不可以?

from codinginterviewchinese2.

woshigerunze avatar woshigerunze commented on June 5, 2024

@WeifaGan你可以定义一个new一个字符串,delete他的指针,但是可以还是可以(有时)cout这个字符串的。delete只是表示这个内存可以被其他人用,但是内容要等下次写入时覆盖,不会立即删除。设置为nullptr可以防止误用(cout delete的指针是未定义行为)

from codinginterviewchinese2.

forwardwfg avatar forwardwfg commented on June 5, 2024

@woshigerunze 原来如此!谢谢解答!

from codinginterviewchinese2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.