Code About Us Tutorial


  Pointers and References
    What are Pointers?
    Declaring Pointers
    The Indirection and Dereference operator
    What is a Reference?
    Using References
    Using Pointers and References
    The new Keyword
    The delete Keyword
    Passing By Reference
    Passing by Value


   
 

Home > Pointers and References > Using Pointers and References

November 30, 2009 12:48 pm

   

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.



Add Comment:
Name:
Email:


 «