Deleting a pointer in C++

后端 未结 6 1353
旧巷少年郎
旧巷少年郎 2020-11-28 01:11

Context: I\'m trying to wrap my head around pointers, we just saw them a couple of weeks ago in school and while practicing today I ran into a silly? issue, it can be super

6条回答
  •  情深已故
    2020-11-28 02:12

    1. You are trying to delete a variable allocated on the stack. You can not do this
    2. Deleting a pointer does not destruct a pointer actually, just the memory occupied is given back to the OS. You can access it untill the memory is used for another variable, or otherwise manipulated. So it is good practice to set a pointer to NULL (0) after deleting.
    3. Deleting a NULL pointer does not delete anything.

提交回复
热议问题