Data Structures Using C++ 2E

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Advanced Piloting Cruise Plot.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 10 second questions
Solve Multi-step Equations
1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure Definitions 10.3Initializing Structures 10.4Accessing.
Chapter 17 Linked Lists.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
Data Structures Using C++
ABC Technology Project
2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure.
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
VOORBLAD.
BIOLOGY AUGUST 2013 OPENING ASSIGNMENTS. AUGUST 7, 2013  Question goes here!
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
© 2012 National Heart Foundation of Australia. Slide 2.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Chapter 5 Test Review Sections 5-1 through 5-4.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 14 - Advanced C Topics Outline 14.1Introduction 14.2Redirecting Input/Output on UNIX and DOS Systems.
25 seconds left…...
Januar MDMDFSSMDMDFSSS
Week 1.
Analyzing Genes and Genomes
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
1 Chapter 3:Operators and Expressions| SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2006 | Last Updated: July 2006 Slide 1 Operators and Expressions.
Intracellular Compartments and Transport
PSSA Preparation.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
CpSc 3220 Designing a Database
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
Pointer Data Type and Pointer Variables
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Addresses in Memory When a variable is declared, enough memory to hold a value of that type is allocated for it at an unused memory location. This is.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
C++ Programming: From Problem Analysis to Program Design, Second Edition1 Objectives In this chapter you will: Learn about the pointer data type and pointer.
C++ Data Types Structured array struct union class Address pointer reference Simple IntegralFloating char short int long enum float double long double.
1 CS 132 Spring 2008 Chapter 3 Pointers and Array-Based Lists read p
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Pointer and Array Lists Chapter 3, Summary CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 14: Pointers.
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists.
You learned how to declare pointer variables how to store the address of a variable into a pointer variable of the same type as the variable how to manipulate.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes
Presentation transcript:

Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists Data Structures Using C++ 2E C++ has three types of data Simple Structured Pointers 1

Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists Data Structures Using C++ 2E 2

The Pointer Data Type and Pointer Variables Declaring pointer variables Specify data type of value stored in location pointer variable points to General syntax dataType *identifier; Asterisk symbol (*) Examples: int *p; and char *ch; Data Structures Using C++ 2E

The Pointer Data Type and Pointer Variables (cont’d.) Address-of operator (&) Unary operator Returns address of its operand Dereferencing operator (*) Different from binary multiplication operator Also known as indirection operator Refers to object where the pointer points (operand of the *) Data Structures Using C++ 2E

The Pointer Data Type and Pointer Variables (cont’d.) Pointers and classes Dot operator (.) Higher precedence than dereferencing operator (*) Member access operator arrow ( ->) Simplifies access of class or struct components via a pointer What’s difference between struct & class? Syntax pointerVariableName -> classMemberName Data Structures Using C++ 2E

The Pointer Data Type and Pointer Variables (cont’d.) Initializing pointer variables No automatic variable initialization in C++ Pointer variables must be initialized If not initialized, they do not point to anything Initialized using Constant value 0 (null pointer) Named constant NULL Number 0 Only number directly assignable to a pointer variable Data Structures Using C++ 2E

The Pointer Data Type and Pointer Variables (cont’d.) Some C++ matters What’s the difference between a struct and a class? What’s a memory leak? Data Structures Using C++ 2E

The Pointer Data Type and Pointer Variables (cont’d.) Some examples involving pointers Playing with Pointers Example 3-2 page 135 Example 3-3 page 142 Data Structures Using C++ 2E

The Pointer Data Type and Pointer Variables (cont’d.) Various List Data Types Array lists Linked lists Doubly linked lists Data Structures Using C++ 2E

The Pointer Data Type and Pointer Variables (cont’d.) Dynamic variables Variables created during program execution Real power of pointers Two operators new: creates dynamic variables delete: destroys dynamic variables Reserved words Data Structures Using C++ 2E

The Pointer Data Type and Pointer Variables (cont’d.) Operator new Allocates single variable Allocates array of variables Syntax new dataType; new dataType[intExp]; Allocates memory (variable) of designated type Returns pointer to the memory (allocated memory address) Allocated memory: uninitialized Data Structures Using C++ 2E

The Pointer Data Type and Pointer Variables (cont’d.) Operator delete Destroys dynamic variables Syntax delete pointerVariable; delete [ ] pointerVariable; Memory leak Memory space that cannot be reallocated Dangling pointers Pointer variables containing addresses of deallocated memory spaces Avoid by setting deleted pointers to NULL after delete Data Structures Using C++ 2E

The Pointer Data Type and Pointer Variables (cont’d.) Operations on pointer variables Operations allowed Assignment, relational operations; some limited arithmetic operations Can assign value of one pointer variable to another pointer variable of the same type Can compare two pointer variables for equality Can add and subtract integer values from pointer variable Danger Accidentally accessing other variables’ memory locations and changing content without warning Data Structures Using C++ 2E

The Pointer Data Type and Pointer Variables (cont’d.) Data Structures Using C++ 2E

Text

Text

Text

Text

Text

Text

Text

Text

Text

Text

Text

Text

Text

Text

Text

Text