Home » Size of a Variable

Size of a Variable

Learn about Size of a Variable in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

The sizeof() operator is the most frequently used operator in C. It is a unary operator that is used to compute the size of its operand at compile time. It returns the variable’s size. It can be used to any data type, including float and pointer variables.

Size of a Variable

The size of a variable is entirely determined by the variable’s data type. If a variable is of the data type int, its size will be 2 or 4 bytes ( Because the size of int is 2 or 4 bytes).


int main()
     int x = 10;
     char c;
     printf("Size of variable x = %ld bytes\n",sizeof(x));
     printf("Size of variable c = %ld byte\n",sizeof(c));
     return 0;


Size of variable x = 4 bytes
Size of variable c = 1 byte

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C Program to Find Size of Data Types
Hello World Program in C