C++变量的大小

# include <iostream>
using namespace std;

int main() 
{
	cout << "========== BASIC VARIABLES SIZE LIST ==========" << endl;
	cout << "short: " << sizeof(short) << " bytes" << endl;
	cout << "int: " << sizeof(int) << " bytes" << endl;
	cout << "long: " << sizeof(long) << " bytes" << endl;
	cout << "long long: " << sizeof(long long) << " bytes" << endl;
	cout << "boolean: " << sizeof(bool) << " byte" << endl;
	cout << "float: " << sizeof(float) << " bytes" << endl;
	cout << "long float: " << sizeof(long float) << " bytes" << endl;
	cout << "double: " << sizeof(double) << " bytes" << endl;
	cout << "long double: " << sizeof(long double) << " bytes" << endl;
	cout << "char: " << sizeof(char) << " byte" << endl;
	cin.get();
}
========== BASIC VARIABLES SIZE LIST ==========
short: 2 bytes
int: 4 bytes
long: 4 bytes
long long: 8 bytes
boolean: 1 byte
float: 4 bytes
long float: 8 bytes
double: 8 bytes
long double: 8 bytes
char: 1 byte
posted @ 2023-04-24 21:42  顺心无忧  阅读(43)  评论(0编辑  收藏  举报