This preview shows page 1. Sign up to view the full content.
Unformatted text preview: r.
• * Dereferencing. *ptr returns the value of
the object that ptr points to.
7 Address of Operator
& 8 Dereferencing Operator
* The address of operator “&” returns the
address of an object. The Dereferencing Operator “*” returns the
value of an object to which its operand points. Example: &joe returns the address of the
variable joe and not the value of it.
Example: ptr = &joe assigns the pointer ptr
to point to the variable joe. Example:
int object = 5;
ptr = &object; // ptr points to address of object
cout << *ptr; // sends 5 to the screen 9 new POINTER INITIALIZATION
int x = 5; 10 // declared ptr, value undefined.
// declared variable. • A C++ operator that creates a new object of
the type that this pointer can point to;
• Returns a pointer to that new object. cout << x;
// sends 5 to screen.
cout << *ptr; // wrong! Pointer not initialized!
ptr = &x;
// ptr now points to the address of x.
cout << *ptr; // right! sends 5 to screen.
View Full Document
This document was uploaded on 03/31/2014 for the course CS 114 at NJIT.
- Spring '09
- Assembly Language