sizeof
operator is used to find the size of int
, long
, long long
, double
and long double
variables.long int
and long double
variables are larger than int
and double
variables, respectively.sizeof
operator returns size_t
(unsigned integral type).size_t
data type is used to represent the size of an object. The format specifier used for size_t
is %zu
.long
keyword cannot be used with float
and char
types.#include <stdio.h>
int main() {
int a;
long b; // equivalent to long int b;
long long c; // equivalent to long long int c;
double e;
long double f;
printf("Size of int = %zu bytes \n", sizeof(a));
printf("Size of long int = %zu bytes\n", sizeof(b));
printf("Size of long long int = %zu bytes\n", sizeof(c));
printf("Size of double = %zu bytes\n", sizeof(e));
printf("Size of long double = %zu bytes\n", sizeof(f));
return 0;
}
Size of int = 4 bytes
Size of long int = 8 bytes
Size of long long int = 8 bytes
Size of double = 8 bytes
Size of long double = 16 bytes