Declaring Pointers
Now that we understand that every variable has an address, we will go on and learn about how to store this address into another variable (a pointer).
The syntax of a pointer is as follows:
Type *pointer-name = &variable-name;
This syntax is for assigning a pointer the memory address of another variable, here is what it looks like.
 | |  | | |
#include <iostream.h>
int main()
{
int n = 10; //variable
int *p = &n;
cout <<"Here is the address of n: " << &n << endl;
cout <<"Here is the value of n: " << n << "n";
cout <<"Here is the value of *p: " << *p << "n";
return 0;
} |
|  |
|
As you can see, the value is the same, because the pointer was holding the value of n.
Please Rate this Code: