其他数据类型数据类型存储大小
时间: 2024-02-27 22:49:24 浏览: 20
以下是一些常见数据类型的存储空间大小的示例:
1. 整型数据类型的存储空间大小:
```cpp
#include <iostream>
using namespace std;
int main() {
cout << "Size of int: " << sizeof(int) << " bytes" << endl;
cout << "Size of short: " << sizeof(short) << " bytes" << endl;
cout << "Size of long: " << sizeof(long) << " bytes" << endl;
cout << "Size of long long: " << sizeof(long long) << " bytes" << endl;
return 0;
}
```
2. 浮点型数据类型的存储空间大小:
```cpp
#include <iostream>
using namespace std;
int main() {
cout << "Size of float: " << sizeof(float) << " bytes" << endl;
cout << "Size of double: " << sizeof(double) << " bytes" << endl;
cout << "Size of long double: " << sizeof(long double) << " bytes" << endl;
return 0;
}
```
3. 字符型数据类型的存储空间大小:
```cpp
#include <iostream>
using namespace std;
int main() {
cout << "Size of char: " << sizeof(char) << " byte" << endl;
cout << "Size of wchar_t: " << sizeof(wchar_t) << " bytes" << endl;
return 0;
}
```
4. 布尔型数据类型的存储空间大小:
```cpp
#include <iostream>
using namespace std;
int main() {
cout << "Size of bool: " << sizeof(bool) << " byte" << endl;
return 0;
}
```