Ch12 Pointers
Ch12 Pointers
Pointers
Objectives
• In this chapter, you will:
– Learn about the pointer data type and pointer
variables
– Explore how to declare and manipulate pointer
variables
– Learn about the address of the operator and the
dereferencing operator
– Learn how pointers work with classes and structs
– Discover dynamic variables
• Examples:
int *p;
char *ch;
• These statements are equivalent:
int *p;
int* p;
int * p;
C++ Programming: From Problem Analysis to Program Design, Seventh Edition 5
Declaring Pointer Variables (cont’d.)
• In the statement:
int* p, q;
– Only p is a pointer variable
– q is an int variable
• Thus,
(*studentPtr).gpa = 3.9;
is equivalent to:
studentPtr->gpa = 3.9;
int* testExp(...)
{
. . .
}