刷题的时候,题目会给出变量的范围,这个时候就要想清楚用哪个类型
#include<iostream> using namespace std; int main(){ int d2 = (1<<31)-1; int d0
= 10; long l2 = ((long)1<<31)-1; long l0 = 10; long long ll2 = ((long
long)1<<63)-1; long long ll0 = 10; for(int i = 0; i<8; i++) d0*=10;//即10^9
for(int i = 0; i<8; i++) l0*=10;//即10^9 for(int i = 0; i<17; i++)
ll0*=10;//即10^18 cout<< d2 << " (int的最大值)" <<endl; cout<< d0 << " (对应10^9)"
<<endl; cout<< l2 << " (long的最大值)" <<endl; cout<< l0 << " (对应10^9)" <<endl;
cout<< ll2 << " (long long的最大值)" <<endl; cout<< ll0 << " (对应10^18)" <<endl;
return 0; }
输出结果为:

技术
今日推荐
PPT
阅读数 135
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信