CSC209H1 Lecture Notes - Lecture 8: Null Pointer, Uninitialized Variable, Dangling Pointer

42 views11 pages
14 Dec 2016
School
Course
Professor

Document Summary

Pointers solve two common problems: allow different sections of code to share information, without copying it, enable complex linked data structures like linked lists and binary trees. We pay a price for using pointers though. 5 common types of bugs: using uninitialized memory bad pointer. 2. trespassing on someone else"s memory over ow. 3. loosing pointer to memory storage memory leak. 4. irresponsible function callers memory leak: accessing memory declared as free dangling pointer. Referencing: int i = 8; int *ip; ip = &i; int **ipp; ipp = &ip; *ipp = ip is 16 ipp is 128. Freshly declared variables are initialized to whatever junk value was present i n the location that the memory contained. We never declare the location in memory that ageptr points to. So when we try to set it to 1234, we actually set the location of where the pointer should be to 1234. This will access some random memory, and destroy it.

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