#include <iostream>
using namespace std;
int main() {
// 整型 (Integer Types)
int a = 10; // 通常为32位,范围大约是 -2^31 到 2^31-1
short b = 20; // 通常为16位,范围大约是 -2^15 到 2^15-1
long c = 30; // 通常为32或64位,范围大约是 -2^31 到 2^31-1 或更大
long long d = 40; // 通常为64位,范围大约是 -2^63 到 2^63-1
// 浮点型 (Floating Point Types)
float e = 3.14f; // 单精度浮点数,通常为32位
double f = 3.141592; // 双精度浮点数,通常为64位
long double g = 3.141592653589793238L; // 扩展精度浮点数,通常为80位或更多
// 字符型 (Character Types)
char h = 'A'; // 单个字符,通常是8位
wchar_t i = L'Ω'; // 宽字符,通常是16位或32位
char16_t j = u'Ω'; // UTF-16编码的字符
char32_t k = U'Ω'; // UTF-32编码的字符
// 布尔型 (Boolean Type)
bool l = true; // 布尔值,true 或 false
// 输出示例
cout << "整型: " << a << ", " << b << ", " << c << ", " << d << endl;
cout << "浮点型: " << e << ", " << f << ", " << g << endl;
cout << "字符型: " << h << ", " << i << ", " << j << ", " << k << endl;
cout << "布尔型: " << l << endl;
return 0;
}
int, short, long, 和 long long。它们用于存储整数值,范围从非常小到非常大。float, double, 和 long double。它们用于存储带有小数部分的数值,精度依次增加。char, wchar_t, char16_t, 和 char32_t。它们用于存储单个字符,支持不同编码格式(如ASCII、UTF-16、UTF-32)。bool 类型用于表示逻辑值 true 和 false。这段代码展示了 C++ 中常见的基本数据类型及其使用方法,并通过 cout 输出了这些类型的值。
上一篇:c++开方函数
下一篇:c++ swap函数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站