Problems with pointers

Slides:



Advertisements
Similar presentations
Recursive binary search
Advertisements

For loops.
Templates.
Introduction to classes
Static variables.
Default values of parameters
Pointers.
Dynamically allocating arrays
Anatomy of a program.
Switch statement.
Command-line arguments
Pointer arithmetic.
Console input.
Dangling pointers.
Hello world!.
This.
Sorted arrays.
Floating-point primitive data types
Dynamically allocating arrays within structures
Dynamic memory allocation
Break statements.
Linked Lists.
Wild pointers.
The comma as a separator and as an operator
Selection sort.
Identifiers.
Bucket sort.
The ternary conditional operator
Dynamically allocating structures
Memory leaks.
Pushing at the back.
Bit-wise and bit-shift operators
Sorting algorithms.
Command-line arguments
Passing pointers as parameters to and from functions
Repetitious operations
Dynamically allocating arrays
Insertion sort.
A list-size member variable
Protecting pointers.
Dynamically allocating arrays
Code-development strategies
Throwing exceptions.
Anatomy of a program.
Selection sort.
Insertion sort.
Pointers as arguments and return values
Addresses and pointers
Default values of parameters
Pointer arithmetic.
Recursive functions.
Class variables and class functions
Operator overloading.
Dynamic allocation of arrays
Templates.
Insertion sort.
Sorted arrays.
Sorting algorithms.
Issues with classes.
Dangling pointers.
Dynamic allocation of classes
Encapsulation.
Destructors.
Counting sort.
Selection sort.
Searching and sorting arrays
Protecting pointers.
An array class: constructor and destructor
This.
Recursive binary search
Presentation transcript:

Problems with pointers

Outline In this lesson, we will: Introduce some of the problems with pointers

Problems with pointers The operating system (os) allocates memory to executing programs Dynamically allocated memory relies on addresses It is very possible to either Have a pointer that for some reason has an invalid address Loose track of addresses that have been allocated due to local variables storing those addresses going out of scope

Problems with pointers We will look at three different situations: Pointers that are not initialized properly wild pointers Pointers that store the address of memory no longer allocated dangling pointers Losing the address of memory allocated to your program memory leaks These issues will, no doubt, continue to be a source of frustration in this course, in future courses, and throughout your professional career

Summary Following this lesson, you now Understand there are issues with pointers We will look at these issues in each of the next three lessons

References [1] No references?

Colophon These slides were prepared using the Georgia typeface. Mathematical equations use Times New Roman, and source code is presented using Consolas. The photographs of lilacs in bloom appearing on the title slide and accenting the top of each other slide were taken at the Royal Botanical Gardens on May 27, 2018 by Douglas Wilhelm Harder. Please see https://www.rbg.ca/ for more information.

Disclaimer These slides are provided for the ece 150 Fundamentals of Programming course taught at the University of Waterloo. The material in it reflects the authors’ best judgment in light of the information available to them at the time of preparation. Any reliance on these course slides by any party for any other purpose are the responsibility of such parties. The authors accept no responsibility for damages, if any, suffered by any party as a result of decisions made or actions based on these course slides for any other purpose than that for which it was intended.