Program to find memory space allocation for data-types

Whenever we declare a variable in C, compiler will allocate storage space in the computer’s memory. For example, if we declare a variable as “int”, 32-bit C compiler will allocate 4 bytes of memory space.

Below is the program in C which displays memory storage space allocated by C compiler as per data-type.Following data types are covered in the below C program:

  • int
  • float
  • short int
  • double
  • signed int
  • unsigned int
  • long int
  • long long int
  • double
  • long double
  • signed short int
  • signed long int
  • unsigned short int
  • unsigned long int
  • unsigned long long int
  • char
  • signed char
  • unsigned char
#include <stdio.h>
#include <stdlib.h>

int main()
{

    printf("\nSize of int is %d", sizeof(int));
    printf("\nSize of float is %d", sizeof(float));
    printf("\nSize of short int is %d", sizeof(short int));

    printf("\nSize of signed int is %d", sizeof(signed int));
    printf("\nSize of unsigned int is %d", sizeof(unsigned int));

    printf("\nSize of long int is %d", sizeof(long int));
    printf("\nSize of long long int is %d", sizeof(long long int));
    printf("\nSize of double is %d", sizeof(double));
    printf("\nSize of long double is %d", sizeof(long double));

    printf("\nSize of signed short int is %d", sizeof(signed short int));
    printf("\nSize of signed long int is %d", sizeof(signed long int));
    printf("\nSize of unsigned short int is %d", sizeof(unsigned short int));
    printf("\nSize of unsigned long int is %d", sizeof(unsigned long int));
    printf("\nSize of unsigned long long int is %d", sizeof(unsigned long long int));


    printf("\nSize of char is %d", sizeof(char));
    printf("\nSize of signed char is %d", sizeof(signed char));
    printf("\nSize of unsigned char is %d", sizeof(unsigned char));

    return 0;
}

Output (from 32-bit C compiler):

Data type size in C
Data type size in C

You may also like...

1 Response

  1. August 5, 2020

    […] Program to find memory allocation size of C data-types […]

Leave a Reply

Your email address will not be published. Required fields are marked *

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet