introduction to c++ - computer sciencetadavis/cs303/cppsf.pdf · introduction 2 −c++ ... −first...
TRANSCRIPT
![Page 1: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/1.jpg)
Introduction to C++
with content from www.cplusplus.com
![Page 2: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/2.jpg)
Introduction
2
−C++
−widely-used general-purpose programming language
−____________
−procedural and object-oriented support
−strong support
−created by Bjarne Stroustrup starting in 1979
−based on C
−first called “C with Classes”
−also with inheritance, , default function
arguments, and strong type checking
−many programs compile with C++ compiler
−major releases in 1983, 1989, 1998, 2011 (C++11)
![Page 3: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/3.jpg)
Structure of a C++ Program
3
![Page 4: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/4.jpg)
Structure of a C++ Program
4
−previous program could also be written as follows
![Page 5: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/5.jpg)
Structure of a C++ Program
5
− two styles of ______________
![Page 6: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/6.jpg)
Structure of a C++ Program
6
−_______________
![Page 7: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/7.jpg)
Identifiers
7
−similar to rules for identifiers
−_________________________
−keywords
![Page 8: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/8.jpg)
Types
8
− fundamental types
![Page 9: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/9.jpg)
Variables
9
−must be _______________
![Page 10: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/10.jpg)
Initializing Variables
10
−different ways to initialize variables at _______________
![Page 11: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/11.jpg)
Variables
11
−automatic deduction
−with initialization
−without initialization
−used in cases where type cannot be obtained easily for
___________________
![Page 12: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/12.jpg)
Strings
12
![Page 13: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/13.jpg)
Literals
13
− integers
− floats
−chars
![Page 14: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/14.jpg)
Literals
14
−escape sequences
![Page 15: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/15.jpg)
Constants
15
− constants
![Page 16: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/16.jpg)
Constants
16
−#define constants
![Page 17: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/17.jpg)
Increment/Decrement
17
−_________________________
![Page 18: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/18.jpg)
Operators
18
− if a=2, b=3, c=6
−AND/OR
−other work similarly to Python
![Page 19: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/19.jpg)
Ternary Operator
19
−condition ? result1 : result2
![Page 20: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/20.jpg)
Bitwise Operators
20
![Page 21: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/21.jpg)
Type Casting
21
−both OK
![Page 22: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/22.jpg)
Operator Precedence
22
![Page 23: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/23.jpg)
Input/Output
23
![Page 24: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/24.jpg)
Input/Output
24
![Page 25: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/25.jpg)
if Statements
25
− if
![Page 26: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/26.jpg)
Iteration
26
− statement
![Page 27: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/27.jpg)
Iteration
27
−do-while statement
![Page 28: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/28.jpg)
Iteration
28
− loop
![Page 29: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/29.jpg)
Iteration
29
− for loop
![Page 30: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/30.jpg)
break Statement
30
−break
![Page 31: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/31.jpg)
continue Statement
31
−continue
![Page 32: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/32.jpg)
switch Statement
32
![Page 33: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/33.jpg)
Functions
33
![Page 34: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/34.jpg)
Functions
34
![Page 35: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/35.jpg)
Functions
35
![Page 36: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/36.jpg)
Functions
36
− return value from ______________
![Page 37: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/37.jpg)
Functions
37
−pass by vs. pass by reference
![Page 38: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/38.jpg)
Functions
38
− functions
![Page 39: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/39.jpg)
Functions
39
− values for parameters
![Page 40: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/40.jpg)
Functions
40
− function ___________
![Page 41: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/41.jpg)
Functions
41
−_________________
![Page 42: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/42.jpg)
Scope
42
− vs. local variables
−general rule: DO NOT USE
![Page 43: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/43.jpg)
Scope
43
− can only represent one entity
![Page 44: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/44.jpg)
Scope
44
− scope
![Page 45: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/45.jpg)
Arrays
45
− memory locations
![Page 46: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/46.jpg)
Initializing Arrays
46
−elements not automatically initialized, but can be _________
initialized
![Page 47: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/47.jpg)
Initializing Arrays
47
− if { } are present, values are to default values
![Page 48: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/48.jpg)
Initializing Arrays
48
− initialized arrays without are automatically sized to
accommodate values
−can be initialized without =
−no error if range _________________
−example uses of arrays
![Page 49: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/49.jpg)
Arrays
49
![Page 50: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/50.jpg)
Multidimensional Arrays
50
−arrays of arrays
![Page 51: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/51.jpg)
Multidimensional Arrays
51
−can be any , but space increases ___________
−allocates a char for each second in the last century
−consumes 3GB of memory
−could have been implemented as a single-dimension array
![Page 52: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/52.jpg)
Multidimensional Arrays
52
![Page 53: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/53.jpg)
Arrays as Parameters
53
![Page 54: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/54.jpg)
Character Arrays
54
−sets aside space, but not ________________
![Page 55: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/55.jpg)
Character Arrays
55
−can initialize with individual elements or literals
−not valid
−OK
![Page 56: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/56.jpg)
Strings and Character Arrays
56
![Page 57: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/57.jpg)
Strings and Character Arrays
57
−can be transformed one to another
![Page 58: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/58.jpg)
Pointers
58
−pointer – the of something
−exact memory locations unknown at time
−use & to get the of a variable
![Page 59: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/59.jpg)
Pointers
59
−use * to get the at a pointer (address)
![Page 60: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/60.jpg)
Pointers
60
−& and * are _________________________
−with following assignments
−all of the following are true
![Page 61: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/61.jpg)
Declaring Pointers
61
−all are the same in memory
−different
![Page 62: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/62.jpg)
Pointers
62
![Page 63: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/63.jpg)
Pointers
63
![Page 64: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/64.jpg)
Pointers and Arrays
64
− with no index is a pointer to the first element
−arrays can always be converted to _______________
−not valid to go the other way
![Page 65: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/65.jpg)
Pointers and Arrays
65
v
![Page 66: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/66.jpg)
Pointers and Arrays
66
−array with is a simply a pointer with an _______
−can be represented with pointer
![Page 67: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/67.jpg)
Pointer Initialization
67
−pointers can be initialized at __________________
−same as
−not valid
−OK
![Page 68: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/68.jpg)
Pointer Arithmetic
68
−pointers can be used in expressions, with
underlying taken into account
−suppose the following have addresses 1000, 2000, 3000
−after the following
−values are 1001, 2002, 3004
−same results for
![Page 69: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/69.jpg)
Pointer Arithmetic
69
− the following is equivalent to ____________
−other examples
− done before increment
−same as
![Page 70: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/70.jpg)
Pointers and const
70
− if value pointed to is const, it cannot be _______________
−pointers can be const
−same
![Page 71: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/71.jpg)
Pointers and const
71
−pointers are not , so can be modified
![Page 72: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/72.jpg)
Pointers to Pointers
72
![Page 73: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/73.jpg)
void Pointers
73
−void pointers point to no particular ______________
![Page 74: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/74.jpg)
Pointers
74
−pointers can point to any ________________
−pointers can point to __________________
−or simply
− pointers and void pointers are different
![Page 75: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/75.jpg)
Dynamic Memory
75
−memory can be allocated during with new
−can check for success/failure
![Page 76: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/76.jpg)
Dynamic Memory
76
−memory can (and should) be during run time
with delete
−can also use (from C), but don’t
mix
![Page 77: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/77.jpg)
Dynamic Memory
77
![Page 78: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/78.jpg)
Data Structures
78
−struct
−or
−access
![Page 79: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/79.jpg)
Data Structures
79
![Page 80: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/80.jpg)
Data Structures
80
![Page 81: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/81.jpg)
Data Structures
81
![Page 82: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/82.jpg)
Data Structures
82
−pointers to _________________
−different from
![Page 83: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/83.jpg)
Data Structures
83
− structs
−access
![Page 84: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/84.jpg)
Other Data Structures
84
− type ________________
−can be used as
−with clause
![Page 85: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/85.jpg)
Other Data Structures
85
−union
−can be accessed as
![Page 86: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/86.jpg)
Other Data Structures
86
−union
![Page 87: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/87.jpg)
Other Data Structures
87
−anonymous union
![Page 88: Introduction to C++ - Computer Sciencetadavis/cs303/cppsf.pdf · Introduction 2 −C++ ... −first called “C with Classes ... Other Data Structures 84](https://reader031.vdocuments.mx/reader031/viewer/2022022016/5b758f1f7f8b9a634c8d916b/html5/thumbnails/88.jpg)
Enumerated Types
88
−can assign integer values (assigned anyway starting at )