Understanding Pointers

Computers use their memory foe storing the instruction of the program and the variables and constants associated with it. The computer’s memory is organized is sequential memory locations of one byte each. Each byte in the memory is associated with a unique location number (i.e., called as address). Typically, the addresses are numbered consecutively starting from 0. The last address of the memory depends on the size of the computer’s memory. For example, the representation of memory locations of a computer with 64k memory size is shown in figure.

img

Every data items occupy one or more contiguous memory locations depending on the type of data items. For example, a single character will be stored in one byte of memory space where as an integer takes two contiguous bytes of memory. Consider the following statement:

int k = 25

This statement finds two bytes of contiguous memory locations for the variable k and stores the value 25 in that location. Assume that the memory locations of k I 2001. This can be represented in figure.

img

Since memory locations are unsigned integers, then can be assigned other variables, which can be stored in memory, like any other variables. Such variable that hold memory locations are called pointer variables. So, we can define a pointer variable is a variable, which can store the address of another variable. Suppose, we can assign the address of the variable k to a pointer variable ptr. Assume the address of the pointer variable ptr is 3001, and then the values of these two variables and their relationships can be shown in figure.

img

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext