Introduction to Pointers

Understanding Pointers:

Computer’s Memory:
A PC’s RAM consists of many thousands of sequential storage locations, and each location is identified by a unique address. The memory addresses in a given computer range from 0 to a maximum value that depends on the amount of memory installed.
When you’re using your computer, the operating system uses some of the system’s memory. When you’re running a program, the programs code (the machine-language instructions for the program’s various tasks) and data (the information the program is using) also use some of the system’s memory.
Declaring and Initializing Pointers:
Consider the Declaration: int i =10;
1) The declaration tells compiler to:
2) Reserve space in memory to hold integer.
3) Associate the name “i” with this memory location.
4) Store value 10 at this location.

  • Address of operator:

1.’&’ is used as address of operator. The expression &i returns the address of i, which is 64532.

  • Value at address:

2.’* ‘is used as value at address of operator.*(&i) gives the value 10.

  • Here printing the valueof *(&i) is same as value of i.
  • The address of i i.e. &i can be collected in a variable j.
  • j = &i
  • Here j is not an ordinary variable. It is variable that contains the address of i.
  • This variable j can be declared as int *j. This is a pointer variable.

Pointers and variable types:

Declaration of pointers
int *p_vint, vint;
char *p_vchar, vchar;
float *p_vfloat, vfloat;

Initialization of pointers
p_vint = &vint;
p_vchar = &vchar;
p_vfloat = &vfloat;

int pointer variable point to the variable of type int. Same is true for char and float pointer variable.

  • The declaration float* ptr doesn’t mean that ptr is going to contain floating point value, What it means that ptr is going to contain address of floating point value.

  • null

    Mr. Sandeep Soni

    Founder, Trainer & CEO, Deccansoft Software Services.

    Sandeep has 21 yrs of experience working in various Microsoft Technologies/Platforms incl. VB6.0, ASP, VC++, VB.NET, C#. He is involved in managing and architecting projects at Deccansoft. He will be your liaison to Deccansoft, for any kind of communication and project updates. He knows what works and what doesn’t, and what practices are most suitable for design and programming with the ultimate goal of producing a quality system.