Well talk about today Pointers Arrays Strings Classes new operator Pointers Stores the memory address where the data is stored int numberPointer Can access the data that is pointed to with ID: 368466
Download Presentation The PPT/PDF document "Pointers and Classes" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Pointers and ClassesSlide2
We’ll talk about today
Pointers
Arrays
Strings
Classes
“new” operatorSlide3
Pointers
Stores the memory address where the data is stored
int
*
numberPointer
;
Can access the data that is pointed to with *
*
numberPointerSlide4
Pointers and references
int
number;
int
*
numberPointer
= &number;
T
wo sides of the same data
numberPointer
Memory address pointed to
*
numberPointer
The value pointed to by
numberPointer
Dereference
number
The value of number
&number
The memory address where number is storedSlide5
Pointers are M
emory AddressesSlide6
Arrays and Pointers
Arrays are pointers to the first element
char*
aString
= char[5];
Equivalent
aString
[3]
*(aString+3)
String
Implemented around a char*
string
anotherString
= “words”;
anotherString
[2] == ‘r’;Slide7
Objects
Same objective as Java
OO-programming
Different syntax
public/private sections
separate declarations and definitions
Operator overloading
We’ll see an example class in the codeSlide8
Objects an Pointers
“new” returns a pointer to the new object
OurClass
*
classPointer
= new
OurClass
();
Don’t need to copy
the entire
object
Needed
for efficiency when working with large data
structures
Pass-by-pointer
By default in Java
C++ give you the option
If you use pointers
obj
->function();