码迷,mamicode.com
首页 > 其他好文 > 详细

测试溢出

时间:2018-08-02 11:16:03      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:namespace   this   算术   赋值   mes   整型   short   测试   color   

 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 }

 

测试溢出

标签:namespace   this   算术   赋值   mes   整型   short   测试   color   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!