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 > What are Pointers?

November 30, 2009 1:25 am

   

What are Pointers?

A pointer is simply a variable that holds a memory address. When a variable is declared, the address of some location in memory, is where the value of the variable is stored. I’ll show you what I’m talking about. In this simple application, I will declare a variable and show you its memory address.

 

 
#include <iostream.h>

int main() { int n; //variable cout <<"Here is the address of n: " << &n << endl; return 0; }

Here we see a new operator, its called the address operator(&). The address of a variable is accessed by means of the address operator. As you can see, we used it here:

 

 
<< &n << endl;

this prints the address of n. The address, 0x0065FDF4 was returned on my computer. Other systems will probably give a different address. Usually programmers don’t need to know the address of the variable, but if they do, just use the & operator! We will be getting more indeph using the address(&) operator shortly.Please Rate this Code:


    Comments for: What are Pointers?
  There are NO user contributed comments for What are Pointers?.



Add Comment:
Name:
Email:


 «1» THINKQUEST TEAM C0111571 © 2001. All Rights Reserved.