C pointer variable memory required



How much Memory required to store Pointer variable?

  1. Pointer Variable Stores the address of the variable
  2. Variable may be integer,character,float but the address of the variable is always integer so Pointer requires 2 bytes of memory in Turbo C Compiler.
  3. If we run same program in any other IDE then the output may differ.
  4. This requirement is different for different Compilers

Program 1: Size of Integer Pointer

#include<stdio.h>

int main()
{
int a = 10, *ptr;
ptr = &a;

printf("\nSize of Integer Pointer : %d",sizeof(ptr));

return(0);
}

Output :

Size of Integer Pointer : 2

Program 2 : Size of Character Pointer

#include<stdio.h>

int main()
{
char a = 'a', *cptr;
cptr = &a;

printf("\nSize of Character Pointer : %d",sizeof(cptr));

return(0);
}

Output :

Size of Character Pointer : 2

Program 3 : Size of Float Pointer

#include<stdio.h>

int main()
{
float a = 3.14, *fptr;
fptr = &a;

printf("\nSize of Character Pointer : %d",sizeof(fptr));

return(0);
}

Output :

Size of Float Pointer : 2