1.整型:int,short,long,long long,char,unsigned int unsigned short....2
.最值:
#include<iostream>
#include<climits>
int main(void)
{
using namespace std;
int n{1};
cout << "n = " << n << endl;
int n_int = INT_MAX;
short n_short = SHRT_MAX;
cout << "int is " << sizeof n_int << " bytes." << endl;
cout << "Maximum value: "
<<"int: " << n_int << endl;
cout << "short is " << sizeof(short) << endl;
cout << "Maximum value: "
<< "short: " << n_short << endl;
return 0;
}
3.越界:
#include<iostream>
#include<climits>
using namespace std;
int main(void)
{
short sam = SHRT_MAX;
unsigned sue = sam;
cout << "sam has " << sam << " dollars and sue has "
<< sue << " dollars" << endl;
sam =sam +1;
sue =sue +1;
cout << "sam has " << sam << " dollars and sue has "
<< sue << " dollars" << endl;
return 0;
}
4.字符以及转义序列的应用:
#include<iostream>
using namespace std;
int main(void)
{
char ch ='M';
int i = ch;
cout << "Char " << ch << " equals " << i << " in int." << endl;
cout << "Add one to " << ch << endl;
ch = ch + 1;
i = ch;
cout << "Char " << ch << " equals " << i << " in int." << endl;
cout << "Display char ch: ";
cout.put(ch);
cout.put('!');
cout << endl << "Done\n";
return 0;
}
本文通过实例讲解了C++中的整数类型(如int, short, long)及其最大值,展示了如何处理数据类型溢出和边界情况,并介绍了字符类型及其转义序列的使用。

被折叠的 条评论
为什么被折叠?



