Using Pointers and References
Here is one last program that uses a pointer and a reference!
 | |  | | |
#include <iostream.h>
int main()
{
int N = 37;
int *pN = &N;
int & rN = *pN;
cout <<"Value of N: " << N << "n";
cout <<"Memory Address of N: " << &N << endl;
cout <<"Value of rN: " << rN << "n";
cout <<"Memory Address of rN: " << &rN << endl;
cout <<"Value of *pN: " << *pN << "n";
return 0;
} |
|  |
|
The lines you need to understand are the top three,
 | |  | | |
int N = 37;
int *pN = &N;
int & rN = *pN; |
|  |
|
The first line creates an integer variable, and is set to 37.
The Second line creates a pointer, and the pointer holds the memory address of N.
The third line creates a reference that holds the address of the pointer.
This means they all have the same value of N, and by modifying one of them, you would change the value of all of them.
Please Rate this Code:
Comments for: Using Pointers and References
There are NO user contributed comments for Using Pointers and References.
|
 |
|
 |