English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Comprehensive Collection of C Programming Examples
In this example, you will learn to use the sizeof operator to evaluate the size of each variable.
#include<stdio.h> int main() { int intType; float floatType; double doubleType; char charType; // Calculate the size of a variable using sizeof printf("The size of int: %ld bytes\n", sizeof(intType)); printf("The size of float: %ld bytes\n", sizeof(floatType)); printf("The size of double: %ld bytes\n", sizeof(doubleType)); printf("The size of char: %ld bytes\n", sizeof(charType)); return 0; }
Output Result
The size of int: 4 bytes The size of float: 4 bytes The size of double: 8 bytes The size of char: 1 bytes
In this program, the following variables are declared4variables intType, floatType, doubleType, and charType.
Then, use the sizeof operator to calculate the size of each variable.