Download presentation
Presentation is loading. Please wait.
1
Pointers and Classes
2
We’ll talk about today Pointers Arrays Strings Classes “new” operator
3
Pointers Stores the memory address where the data is stored
int* numberPointer; Can access the data that is pointed to with * *numberPointer
4
Pointers and references
int number; int* numberPointer = &number; Two 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 stored
5
Pointers are Memory Addresses
6
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’;
7
Objects Same objective as Java Different syntax OO-programming
public/private sections separate declarations and definitions Operator overloading We’ll see an example class in the code
8
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();
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.