Download presentation
Presentation is loading. Please wait.
1
CS148 Introduction to Programming II
Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture 9: 2/14/2003 Lecture 9: 2/14/2003 CS148 Spring 2003
2
Outline What is a pointer data type? Operations on pointers
Lecture 9: 2/14/2003 CS148 Spring 2003
3
What is a pointer data type?
A pointer is a built-in data type (like any other data types, e.g., int, float) A pointer is a reference data type. A pointer variable contains the memory address (location) of another variable 5008 Address Variable Name 5000 intPtr beta Memory intPtr beta Abstract Diagram Lecture 9: 2/14/2003 CS148 Spring 2003
4
Pointer Variables and Operations
Pointer Variable Declaration DataType* Variable; DataType* Variable, *Variable…; Example int* intPtr; //intPtr contains the address of an int variable Pitfall int* p, q; //q here is of type int and not int* Never use a pointer before initializing it Lecture 9: 2/14/2003 CS148 Spring 2003
5
Pointer Variables and Operations
address-of operator (&) int beta; int* intPtr; intPtr = β //separate initialization: memory address of beta is stored into intPtr. Or alternatively int* inPtr = β //initialization with declaration Lecture 9: 2/14/2003 CS148 Spring 2003
6
Pointer Variables and Operations
dereference operator (*) int beta; int* intPtr = β *intPtr = 28; //dereference intPtr and store value 28 into beta. Indirect Addressing of beta 28 intPtr beta Lecture 9: 2/14/2003 CS148 Spring 2003
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.