C size of pointer variable

In the previous chapter, we have learnt about the memory organization of the pointer variable. In this chapter we are learning to compute or find the size of pointer variable.

What is the size of Pointer variable in C ?

Pointer is the variable that stores the address of another variable.

How to calculate size of Pointer ?

Consider the following memory map before declaring the variable.In the memory comprise of blocks of 1 byte.
Step 1 : Memory Before Variable Declaration
Whenever we declare any variable then random block of memory is chosen and value will be stored at that memory location.

Similarly whenever we declare any pointer variable then random block of memory will be used as pointer variable which can hold the address of another variable.

Calculating Size of Pointer : Tips

  1. Pointer stores the address of the Variable.
  2. Size of Pointer Variable can be evaluated by using sizeof operator
  3. Address of variable is considered as integer value.
  4. For Borland C/C++ Compiler, for storing integer value 2 bytes are required.
  5. Thus Pointer variable requires 2 bytes of memory.

Size of Integer Pointer Variable in Different IDE :

CompilerSize of IntegerSize of Integer Pointer
Borland C/C++2 Bytes2 Bytes
Turbo C/C++2 Bytes2 Bytes
Visual C++4 Bytes4 bytes

Size of the Pointer :

#include<stdio.h>
int main()
{
int num = 15;
int *ptr = NULL;
ptr = &num;
printf("Size of Pointer : %d Bytes",sizeof(ptr));
return 0;
}

Output :

Size of Pointer : 2 Bytes

Some of the Useful Programs :