Home » Learn C++ » Pointers in C++

Pointers in C++

Pointers:

            Pointers are the most powerful feature of C & C++. These are used to create and manipulate data structures such as linked lists, queues, stacks, trees etc. The virtual functions also require the use of pointers. These are used in advanced programming techniques. To understand the use of pointers, the knowledge of memory locations, memory addresses and storage of variables in memory is required.

 

Memory Addresses and Variables:

            Computer memory is divided into various locations. Each location consists of 1 byte. Each byte has a unique address. When a program is executed, it is loaded into the memory from the disk. It occupies a certain range of these memory locations. Similarly, each variable defined in the program occupies certain memory locations. For example, an int type variable occupies two bytes and a float type variable occupies four bytes.

            When a variable is created in the memory three properties are associated with it. These are:

 

  • Type of the variable.
  • Name of the variable.
  • Memory address assigned to the variable.

 
For example an integer type variable xyz is declared as shown below:

 

int xyz 6760;
 

 

int represents the data type of the variable.
xyz represents the name of variable.

 

            When a variable is declared; a memory location is assigned to it. Suppose, the memory address assigned to the above variable xyz is 1011.

 

            The memory address where the contents of a specific variable arc stored can also he accessed. The address operator (&) is used with the variable name to access its memory address. The address Operator (&) is used before the variable name.

 

Other Topics

comment closed

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Copyright © 2010 Information Village. All rights reserved.