可以使用sizeof运算符计算出给定类型占用的字节数。以下是如何存储应用sizeof运算符产生的值:

size_t size = sizeof(long long);

该程序将输出每种数字类型占用的字节数:

#include <stdio.h>

int main(void)
{
  printf("Variables of type char occupy %u bytes\n", sizeof(char));
  printf("Variables of type short occupy %u bytes\n", sizeof(short));
  printf("Variables of type int occupy %u bytes\n", sizeof(int));
  printf("Variables of type long occupy %u bytes\n", sizeof(long));
  printf("Variables of type long long occupy %u bytes\n", sizeof(long long));
  printf("Variables of type float occupy %u bytes\n", sizeof(float));
  printf("Variables of type double occupy %u bytes\n", sizeof(double));
  printf("Variables of type long double occupy %u bytes\n", sizeof(long double));
  return 0;
}