Calculation int, float, double, and four kinds of variable size in bytes using char sizeof operator.
sizeof is a C language unary operator, such as the C ++ language of the other operators, - and the like, it does not function.
sizeof operator gives its storage size in bytes of the operand.
#include <stdio.h>
int main()
{
int integerType;
float floatType;
double doubleType;
char charType;
// sizeof 操作符用于计算变量的字节大小
printf("Size of int: %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;
}
Calculating long long, long double byte size
#include <stdio.h>
int main()
{
int a;
long b;
long c;
double e;
long double f;
printf("Size of int = %ld bytes \n", sizeof(a));
printf("Size of long = %ld bytes\n", sizeof(b));
printf("Size of long long = %ld bytes\n", sizeof(c));
printf("Size of double = %ld bytes\n", sizeof(e));
printf("Size of long double = %ld bytes\n", sizeof(f));
return 0;
}