top of page
Search

Write a C Program to Find the Size of a variable?




Write a C Program to Find the Size of a variable?

#include <stdio.h>

int main()

{

int integerType;

float floatType;

double doubleType;

char charType;

/* Sizeof operator is used to evaluate the size of a variable */

printf("Size of Integer: %ld bytes\n",

sizeof(integerType));

printf("Size of Float: %ld bytes\n",

sizeof(floatType));

printf("Size of Double: %ld bytes\n",

sizeof(doubleType));

printf("Size of Char: %ld byte\n",

sizeof(charType));

return 0;

}


Output:

Size of Integer: 4 bytes

Size of Float: 4 bytes

Size of Double: 8 bytes

Size of Char: 1 byte


Explanation:

In this program, there are 4 types of variables: integerType, floatType, doubleType, and charType which are declared having int, float, double and char type respectively.

Then, the size of each variable is ascertained using the sizeof operator.


For Video Explanations Check Out Our Playlist on Youtube HERE.


1,092 views
bottom of page