Home

Overview

Operators

Ex. Code

Errors

Importance

Links


Operators --

For using pointers, we use the ampersand (&) or the star operator (*) to say that we do not want a variable’s value, instead we want its memory location.  These are the ways to declare a pointer.  To assign a reference to x in variable xPointer we would say:

xPointer = &x;  // 'xPointer' points to the memory location of 'x'
Now we know how to create/define pointers and how to assign values to them, but once we assign a value to a pointer, how do we read it? We can read the memory location of a pointer just by looking at its value. Continuing our example:

cout << xPointer;  // Outputs the memory location of x
                            // (i.e.0x0012FF78)

What if we want to retrieve the value of whatever the pointer is referencing? The easiest way is through the star operator. For example:

cout << *xPointer;  // Outputs value of what xPointer is referencing


Group 1: S. Bhatnagar, S. Guruda, K. Kaul, A. Jain