by Dinesh Thakur Category: Operator

The sizeof operator is another method to determine the storage requirements of any data type of variable during the execution of a program. For example, we can use the expression.


to determine the storage requirements of an int variable on our computer. The operator sizeof can also be used on any variable as shown in the example below.

int kk;

printf("sizeof(kk) = %d bytes", sizeof(kk);

The sizeof operator precedes either a variable name OR a datatype name. For example, if x has been declared to be a float variable, then both the expressions given below will yield the number of bytes required to store a float variable.

sizeof (x)

sizeof (float)

using sizeof with a variable name

using sizeof with a datatype

The program, given below will provide the information about the storage of various data types on your C compiler.

#include <stdio.h>
void main()
   printf( "Size of char= %d bytes\n", sizeof(char));
   printf( "Size of short int= %d byte\n", sizeof(short));
   printf( "Size of int= %d byte\n", sizeof(int));
   printf( "Size of long int= %d byte\n", sizeof(long int));
   printf( "Size of long long int= %d byte\n", sizeof(long int));
   printf( "Size of float= %d byte\n", sizeof(float));
   printf( "Size of double= %d byte\n", sizeof(double));
   printf( "Size of long double= %d byte\n", sizeof(long double));
   printf( "Size of enum = %d byte\n", sizeof(enum));

sizeof() operator in C

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.