How much Memory required to store Pointer variable?

March 18, 2012 4 Comments » Hits : 353





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.
  3. 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 : 1

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 : 4

Pointer Variable and Size of Pointer Variable

Incoming search terms:

  • Mrt_kapil

    all answers are 100% wrong because pointer always require only two bytes of memory.
    from kapil kumar verma IIMT Meerut

    • http://www.c4learn.com/ Pritesh

      For Borland C/C++ it requires 2 Bytes…. All Programs are written in Borland C/C++ 3.0

  • Phogatashish

    I think you are wrong in above area……I run your programs in Visual Studio and it comes out to be 4 for all the programs.

    • http://www.c4learn.com/ Pritesh

      If you have read above article , you will find this statement -

      “This requirement is different for different Compilers”

      For Visual Studio – It require 4bytes and for Borland C/C++ it requires 2 Bytes