C program to know storage size of int, char and float

To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes. Following is an example to get the size of int type on any machine.

 $ vim know_size.c 
#include <stdio.h>
#include <limits.h>
int main(int argc, char **argv) {
        printf("Storage size for int : %d \n", sizeof(int));
        printf("Storage size for char : %d \n", sizeof(char));
        printf("Storage size for float : %d \n", sizeof(float));
        return 0;
 $ gcc -o know_size know_size.c 
 $ ./know_size
Storage size for int : 4 
Storage size for char : 1 
Storage size for float : 4 

Leave a Comment