各数据类型取值范围

本文通过一个简单的 C++ 程序展示了不同数据类型的数值范围,包括 short、int、long、unsigned int 和 unsigned long long 等,并通过递增变量的方式测试其边界条件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<iostream>
using namespace std;
int main()
{
    short              a=32767;
    //未超范围(2^15-1)  约等于10^4
    int                b=2147483647;
    //未超范围(2^31-1)  约等于10^9
    long               c=2147483647;
    //未超范围(2^31-1)  约等于10^9
    unsigned int       d=4294967295;
    //未超范围(2^32-1)  约等于10^9
    unsigned long      e=4294967295;
    //未超范围(2^32-1)  约等于10^9
    long long          f=9223372036854775807;
    //未超范围(2^63-1)  约等于10^18
    unsigned long long g=18446744073709551615;
    //未超范围(2^64-1)  约等于10^19
    a++;b++;c++;d++;e++;f++;g++;
    //超范围
    cout<<"各函数范围"<<endl;
    cout<<"shart : "<<endl<<a<<"~";
    a--;
    cout<<a<<endl<<endl;
    cout<<"int : "<<endl<<b<<"~";
    b--;
    cout<<b<<endl<<endl;
    cout<<"long : "<<endl<<c<<"~";
    c--;
    cout<<c<<endl<<endl;
    cout<<"unsigned int : "<<endl<<d<<"~";
    d--;
    cout<<d<<endl<<endl;
    cout<<"unsigned long : "<<endl<<e<<"~";
    e--;
    cout<<e<<endl<<endl;
    cout<<"long long : "<<endl<<f<<"~";
    f--;
    cout<<f<<endl<<endl;
    cout<<"unsigned long long : "<<endl<<g<<"~";
    g--;
    cout<<g<<endl<<endl;
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值