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 
Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home JAVA Programs Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply