C++的类型规模

C++语言中包含不同类型的数据,每种数据类型都有不同的内存占用大小。以下是C++数据类型的规模列表(以字节为单位):

  1. char类型:1字节
  2. short类型:2字节
  3. int类型:4字节
  4. long类型:4或8字节(取决于平台)
  5. long long类型:8字节
  6. float类型:4字节
  7. double类型:8字节
  8. long double类型:16字节
  9. bool类型:1字节(但在内存中通常以4字节存储)

此外,C++还包括指针类型和引用类型,它们的大小也取决于平台。在32位系统上,指针和引用类型占4字节,在64位系统上则占8字节。

#include<iostream>
using namespace std;

int main()
{
    int a;
    long long b;
    short c;
    char d;
    long e;
    float f;
    double g;
    long double h;
    bool i;
    cout << "int :" << sizeof(a) << "bite.\n";
    cout << "long long :" << sizeof(b) << "bite.\n";
    cout << "short :" << sizeof(c) << "bite.\n";
    cout << "char:" << sizeof(d) << "bite.\n";
    cout << "long:" << sizeof(e) << "bite.\n";
    cout << "float :" << sizeof(f) << "bite.\n";
    cout << "double:" << sizeof(g) << "bite.\n";
    cout << "long double:" << sizeof(h) << "bite.\n";
    cout << "bool:" << sizeof(i) << "bite.\n";
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值