不同数据类型在不同编译器下字节大小

int,long int,short int的宽度和机器字长及编译器有关,但一般都有以下规则(ANSI/ISO制订的)

  1. sizeof(short int) <= sizeof(int)
  2. sizeof(int) <= sizeof(long int)
  3. short int至少应为16位(2字节)
  4. long int至少应为32位
数据类型16位编译器32位编译器64位编译器
char 1字节 1字节 1字节
char* 2字节 4字节 8字节
short int 2字节 2字节 2字节
int 2字节 4字节 4字节
unsigned int 2字节 4字节 4字节
float 4字节 4字节 4字节
double 8字节 8字节 8字节
long 4字节 4字节 8字节
long long 8字节 8字节 8字节
unsigned long 4字节 4字节 8字节

(本文内容出自程序喵大人公众号- 面试常考,项目易错,长文详解C/C++中的字节对齐 作者:李肖遥 2020-11-15

posted @ 2021-02-26 21:02  Kaniso_Vok  阅读(91)  评论(0编辑  收藏  举报