2.1 整型
作用:整型变量表示的是整数类型的数据
C++中能够表示整型的类型有以下几种方式,区别自安于所占内存空间不同
数据类型
占用空间
取值范围
short(短整型)
2字节
-2^15~2^15-1
int(整型)
4字节
-2^31~2^31-1
long(长整型)
windows为4字节,linux为4字节(32位),8字节(64位)
-2^31~2^31-1
long long(长长整型)
8字节
-2^63~2^63-1
示例:
#include<iostream>
using namespace std;
int main()
{
//整型
//1、短整型
short num1 = 10;
//2、整型
int num2 = 10;
//3、长整型
long num3 = 10;
//4、长长整型
long long num4 = 10;
cout << num1 << endl;
cout << num2 << endl;
cout << num3 << endl;
cout << num4 << endl;
system("pause");
return 0;
}最后更新于
这有帮助吗?