7.pointers

7.pointers - Dynamic data and pointers definitions...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Dynamic data and pointers [Bono] 1 Dynamic data and pointers • definitions • motivation •n e w • NULL • dangling pointers / address-of • memory leaks •d e l e t e • pointers and class • aliasing
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Dynamic data and pointers [Bono] 2 Definitions •A n address is a location in memory. All data in programs have addresses. •A pointer is a variable that can hold an address dynamic data is memory that is allocated to your program at run-time. –h a s n o n am e – run-time system tells us its address on allocation
Background image of page 2
Dynamic data and pointers [Bono] 3 What are pointers for? • A few different things. First . . . • Pointers used in dynamic data structures – Data structures that can grow and shrink over time • E.g., vectors and strings are implemented in terms of pointers • Linked lists are another one we will study presently • A box-and-pointer diagram for a linked list: 12 3 7 mylist
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 What are pointers for? (cont.) • Pointers used for shared data – Two different objects need access to the same data Class “CS102” . . . Class
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 15

7.pointers - Dynamic data and pointers definitions...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online