首页 > 其他 > 详细

测试溢出

时间:2018-08-02 10:52:50      阅读:164      评论:0      收藏:0      [点我收藏+]
 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int main(int argc, char** argv) {
 6       //声明整型变量
 7     int a,b; 
 8 
 9     //从键盘上为整型变量赋值
10     cout<<"a=";
11     cin>>a;
12     cout<<"b=";
13     cin>>b;
14 
15     //整型数的算术运算
16     cout<<a<<"+"<<b<<"="<<a+b<<endl;
17     cout<<a<<"-"<<b<<"="<<a-b<<endl;
18     cout<<a<<"*"<<b<<"="<<a*b<<endl;
19     cout<<a<<"/"<<b<<"="<<a/b<<endl;
20     cout<<a<<"%"<<b<<"="<<a%b<<endl;
21 
22     //测试溢出
23     short n=32767,m;    //n取short类型的最大值
24     cout<<"n="<<n<<endl;
25     m=n+1;      //引起溢出
26     cout<<"n+1="<<m<<endl;
27     
28     return 0;
29 }

 

测试溢出

原文:https://www.cnblogs.com/borter/p/9405640.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!