Print size of different types Using Pointer in C

Definition:

  • Pointer is the variable that holds the address of another variable.
  • Poniter variable also take same memory of actual data type.

Poniter Syntax: 

pointer_vaibale = &variable;

Sizeof Definition:

sizeof returns the size of a variable or datatype

Sizeof Syntax

sizeof (data_type)

Simple Program for Print size of different types Using Pointer in C

/* Simple Program for Print size of different types Using Pointer in C*/
/* Print Pointer Address Program,C Pointer Examples */

#include <stdio.h>

int main() {
  int a = 10;
  int *pa = &a;

  char b = 'x';
  char *pb = &b;
  
  float c = 10.01;
  float *pc = &c;
  
  double d = 10.01;
  double *pd = &d;
  
  long e = 10.01;
  long *pe = &e;
  
  printf("Pointer Example Program : Print Size of Different types Using sizeof\n");

  printf("\n[sizeof(a)   ]: = %d", sizeof(a));
  printf("\n[sizeof(*pa) ]: = %d", sizeof(*pa));

  printf("\n[sizeof(b)   ]: = %d", sizeof(b));
  printf("\n[sizeof(*pb) ]: = %d", sizeof(*pb));
  
  printf("\n[sizeof(c)   ]: = %d", sizeof(c));
  printf("\n[sizeof(*pc) ]: = %d", sizeof(*pc));
  
  printf("\n[sizeof(d)   ]: = %d", sizeof(d));
  printf("\n[sizeof(*pd) ]: = %d", sizeof(*pd));
  
  printf("\n[sizeof(e)   ]: = %d", sizeof(e));
  printf("\n[sizeof(*pe) ]: = %d", sizeof(*pe));
  
  return 0;
}

Sample Output:

Pointer Example Program : Print Size of Different types Using sizeof

[sizeof(a)   ]: = 4
[sizeof(*pa) ]: = 4
[sizeof(b)   ]: = 1
[sizeof(*pb) ]: = 1
[sizeof(c)   ]: = 4
[sizeof(*pc) ]: = 4
[sizeof(d)   ]: = 8
[sizeof(*pd) ]: = 8
[sizeof(e)   ]: = 4
[sizeof(*pe) ]: = 4


/* Output may vary based on system  */