Chapter 7 - Pointers: Outline
Chapter 7 - Pointers: Outline
Chapter 7 - Pointers: Outline
Outline
7.1 Introduction
7.2 Pointer Variable Declarations and Initialization
7.3 Pointer Operators
7.4 Calling Functions by Reference
7.5 Using the const Qualifier with Pointers
7.6 Bubble Sort Using Call by Reference
7.7 Pointer Expressions and Pointer Arithmetic
7.8 The Relationship between Pointers and Arrays
7.9 Arrays of Pointers
7.10 Case Study: A Card Shuffling and Dealing Simulation
7.11 Pointers to Functions
y yptr y
5 500000 600000 600000 5
yPtr
Address of y
is value of
yptr
suit[1] ’D’ ’i’ ’a’ ’m’ ’o’ ’n’ ’d’ ’s’ ’\0’
– suit array has a fixed size, but strings can be of any size
2000 Prentice Hall, Inc.
All rights reserved.
7.10 Case Study: A Card Shuffling and Dealing
Simulation
• Card shuffling program
– Use array of pointers to strings
– Use double scripted array (suit, face)
Ace Two Three Four Five Six Seven Eight Nine Ten Jack Queen King
0 1 2 3 4 5 6 7 8 9 10 11 12
Hearts 0
Diamonds 1
Clubs 2
Spades 3
Clubs King
66 { Outline
67 return b < a; /* swap if b is less than a */
3.1 Define functions
68 }
69
71 {
73 }