32和64位系统占的字节(int char long double 指针等)

        32位      64位
char      1       1
int       4      大多数4,少数8
long      4       8
float     4       4
double    8       8
指针      4       8

32/64位操作系统,数据类型字节数对比

常用数据类型对应字节数
  可用如sizeof(char),sizeof(char*)等得出

 32位编译器:

      char :1个字节
      char*(即指针变量): 4个字节(32位的寻址空间是2^32, 即32个bit,也就是4个字节。同理64位编译器)
      short int : 2个字节
      int:  4个字节
      unsigned int : 4个字节
      float:  4个字节
      double:   8个字节
      long:   4个字节
      long long:  8个字节
      unsigned long:  4个字节


  64位编译器:

      char :1个字节
      char*(即指针变量): 8个字节
      short int : 2个字节
      int:  4个字节
      unsigned int : 4个字节
      float:  4个字节
      double:   8个字节
      long:   8个字节
      long long:  8个字节
      unsigned long:  8个字节

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
```cpp #include <iostream> int main() { // 打印基本数据类型的大小 std::cout << "sizeof(int): " << sizeof(int) << " bytes" << std::endl; std::cout << "sizeof(float): " << sizeof(float) << " bytes" << std::endl; std::cout << "sizeof(double): " << sizeof(double) << " bytes" << std::endl; std::cout << "sizeof(char): " << sizeof(char) << " bytes" << std::endl; // 打印其他常用数据类型的大小 std::cout << "sizeof(short): " << sizeof(short) << " bytes" << std::endl; std::cout << "sizeof(long): " << sizeof(long) << " bytes" << std::endl; std::cout << "sizeof(long long): " << sizeof(long long) << " bytes" << std::endl; std::cout << "sizeof(bool): " << sizeof(bool) << " bytes" << std::endl; std::cout << "sizeof(wchar_t): " << sizeof(wchar_t) << " bytes" << std::endl; std::cout << "sizeof(char16_t): " << sizeof(char16_t) << " bytes" << std::endl; std::cout << "sizeof(char32_t): " << sizeof(char32_t) << " bytes" << std::endl; // 打印指针类型大小,通常与系统架构有关 std::cout << "sizeof(void*): " << sizeof(void*) << " bytes" << std::endl; std::cout << "sizeof(int*): " << sizeof(int*) << " bytes" << std::endl; // 打印结构体的大小,注意可能有填充字节 struct MyStruct { int i; char c; }; std::cout << "sizeof(MyStruct): " << sizeof(MyStruct) << " bytes" << std::endl; return 0; } ``` 这段代码展示了如何在C++中使用`sizeof`运算符来获取不同数据类型的字节大小。它包括了整型、浮点型、字符类型和其他常用的数据类型,还展示了指针类型以及一个自定义结构体的大小。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值