Introduction
“A pointer in ‘C’ language is a special variable which contains the address of the other variable”. C is a very powerful language because of the pointers available in it, which is one of the unique feature supplied by the C language. Pointers provides the ability to directly access the memory locations as well as it can modify the values present in that memory location through it. Pointers are like the sharp knives, which has to be handle with utmost care in the programming, otherwise leads to serious disaster. On the counterpart, pointers are very useful as well as powerful tool, because pointers are the only way to express the computation and also leads to efficient and compact code.
Memory and Variables
Let we spend some time in understanding, how the variables are stored in the memory through various examples and diagrams.
Example #1: Consider the following definition,
int a = 0xAABBCCDD;
Let we think for a while by putting few questions by ourselves,
Question #1. How much of memory is allocated for the variable ‘a’?
Question #2. How the memory is allocated?
Question #3. How the value is stored in the allocated memory?
From the above definition, it is very clear that we are instructing to the compiler to allocate some memory for the variable ‘a’ and store the hexadecimal value ‘OxAABBCCDD’ in it.
-
From the above definition, it is very clear that we are instructing to the compiler to allocate some memory for the variable ‘a’ and store the hexa decimal value ‘0xAABBCCDD’ in it.
-
So, coming to the first question, how much memory is allocated, it depends on the architecture of the machine.
-
The memory will be allocated contiguously as shown in the below figure-1, the value stored in the memory cells depends on the endianess of the machine. Here, I am making assumption that size of int data type is 4 bytes.

Figure-1: Representation of integer data in the memory
Note-1: In the above figure each block size = 1 byte and the data is stored according to the big endian, so MSB is stored in lower address.
Example #2: Consider another example, as shown below
char ch = ‘A’;
The below figure-2 shows how the memory is allocated for the variable ‘ch’ and how the value ‘A’ is stored in the memory. Sizeof char datatype is 1 byte = block size.

Figure-2: Representation of char data in the memory
Example #3: Consider an example of the float data type,
float f = 12.25;
The below figure-3 shows how the memory is allocated for the float variable ‘f’ and the value 12.25 will be stored in array of 4 bytes from the address 100 onwards, according to the IEEE format.

Figure-3: Representation of the float data in the memory
Example #4: Consider an example of the float data type,
double d = 125.67;
The below figure-4 shows how the memory is allocated for the double variable ‘d’ and the value 125.67 will be stored in array of 8 bytes from the address 100 onwards, according to the IEEE format.

Figure-4: Representation of double data in the memory
From the above 4 different examples, we came to know how the variables are allocated memory depending upon the data type of the variables.