next up previous
Next: Calling Functions with Arrays Up: Pointers Previous: Pointers

Pointer Operators

There are two special operators that are used with pointers * and &. The & is a unary operator that returns the memory address of its operand, for example

bal=&balance;

puts into bal the memory address of the variable balance. This address is the location of the variable in the computer's internal memory. It has nothing to do with the value of balance. The statements can be verbalized as bal receives the address of balance. This operator was used previously in the functions section.

The second operator is *, and it is a complement of &. It is a unary operator that returns the value of the variable at the address specified by its operand. Consider the example below:

value=*balance;

This operation will balce the value of balance into value.

Example

#include <iostream.h>
main()
{
int balance;
int *bal;
int value;

balance=3200;
bal=&balance;
value=*bal;
cout << "Balance is "<< value <<'$\backslash$n';
return 0;
}



Yousef Haik
2/23/1998