130 Introduction to C++ Programming and Graphics
The prefix & in the statements evaluating the pointer variables is the reference
operator. The output of the code is:
4 3219988068
1.2 3219988064
3.45 3219988056
c 3219988055
Alternatively, we could have combined pointer declaration and evaluation
by stating:
int * memada=&a;
float * memadb = &b;
double * memadc=&c;
char * memadd = &d;
Dereference operator
Conversely, we can extract the memory content of a specified memory
address using thedereference operator,*, which should be read: “content of
the memory address ...”; the name of the appended pointer variable should
replace the three dots.
The following statements declare and evaluate an integer, extract its
memory address through a pointer, and then deduce the memory content:
int a=4;
int * memada=&a;
int verifya = * memada;
cout << a <<""<<memada<<""<<verifya << endl;
The prefix*in the statement evaluating the content of the pointer variable is
the dereference operator. The output of the code is:
4 0xbfa6e2c8 4
Note that the memory address is printed in the hexadecimal system.
It is unfortunate that the asterisk is used both in the pointer declaration
and as the dereference operator. It would have been much less confusing if a
different symbol were chosen for the declaration.