CMPSC 16 Lecture Notes - Lecture 13: Dangling Pointer, Linked List

40 views1 pages
20 Nov 2018
School
Course
Professor

Document Summary

Dangling pointer: pointer that points to a memory location that no longer exists. Not pointing to a valid location in memory; if dereferenced, a seg fault will occur. Delete p; //p is no longer pointing at anything because the int on the heap has been freed. Heap memory not deallocated/freed before the end of program. Heap memory that can no longer be accessed. When p contains null, it doesn"t mean that it is a dangling pointer. Dangling pointer is when the pointer is pointing to something that doesn"t make sense such as a value that was created on the stack in a function and then deleted when the function was returned. To make sure p is not a dangling pointer, do p = 0. If there are 2 deletes for the same variable, then there will be a seg fault. If the variable is set to null or 0 inbetween, then there will not be a seg fault.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions