2.1 整型
数据类型存在的意义:给变量分配合适的内存空间
# include <iostream>
using namespace std;
int main() {
short num1 = 10;
int num2 = 10;
long num3 = 10;
long long num4 = 10;
cout << "num1 = " << num1 << endl;
cout << "num2 = " << num2 << endl;
cout << "num3 = " << num3 << endl;
cout << "num4 = " << num4 << endl;
system("pause");
return 0;
}
2.2 sizeof关键字
可以利用sizeof求出数据类型占用内存大小
语法:sizeof(数据类型 / 变量)
# include <iostream>
using namespace std;
int main() {
short num1 = 10;
cout << "short占用内存空间为:" << sizeof(short) << endl;
int num2 = 10;
cout << "int占用内存空间为:" << sizeof(int) << endl;
long num3 = 10;
cout << "long占用内存空间为:" << sizeof(long) << endl;
long long num4 = 10;
cout <<