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):
1 Response
[…] Program to find memory allocation size of C data-types […]