CHP 12 Pointer and Dynamic Values
CHP 12 Pointer and Dynamic Values
Integral
Floating-Point
(int, bool, Enumeration Arrays structs Classes
(double, …)
char, …)
Pointer Variables
• A pointer variable is a variable that contains a
memory address (usually the address of
another variable or of an array).
• Depending on the datatype of the thing whose
address the pointer contains, we call the
pointer a pointer-to-int, or a pointer-to-
double, and so on.
• Examples:
int *myPtr1; //Declares a pointer-to-int.
char *myPtr2; //Declares a pointer-to-
char.
• In these examples, the names of the pointers
we’re declaring are myPtr1 and myPtr2, not
*myPtr1 and *myPtr2.
C++ Programming: From Problem Analysis to Program Design, Seventh Edition 14
We’re Not Multiplying Anything
• The previous examples:
int *myPtr1; //Declares a pointer-to-int.
char *myPtr2; //Declares a pointer-to-
char.
• Note that * is also the multiplication operator, but
we’re using the symbol * here in a way that has
nothing to do with multiplication.
p x
34