C program to find the size of int, float, double and char

Given four types of variables, namely int, char, float and double. The task is to write a program to find the size of these four types of variables in C.

sizeof

Examples:

Input: int
Output: Size of int = 4

Input: double
Output: Size of double = 8


In the below program, to find the size of the four variables, first the four types of variables are defined in integerType, floatType, doubleType and charType. Then, the size of the variables are calculated using sizeof() operator.

Below is the C program to find the size of int, char, float and double datatypes:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C program to find the size of int, char,
// float and double datatypes
  
#include <stdio.h>
  
int main()
{
    int integerType;
    char charType;
    float floatType;
    double doubleType;
  
    // Calculate and Print the size of integerType
    printf("Size of int is: %ld\n", integerType);
  
    // Calculate and Print the size of charType
    printf("Size of char is: %ld\n", charType);
  
    // Calculate and Print the size of floatType
    printf("Size of floatType is: %ld\n", floatType);
  
    // Calculate and Print the size of doubleType
    printf("Size of double is: %ld\n", doubleType);
  
    return 0;
}

chevron_right


Output:

Size of int is: 4
Size of char is: 1
Size of floatType is: 4
Size of double is: 8


My Personal Notes arrow_drop_up

Technical Content Engineer

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.