3.1 limits.cpp
2022/1/16 6:08:32
本文主要是介绍3.1 limits.cpp,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
目录- 3.1 limits.cpp
- 1 程序清单 3.1
- 2 注意事项
3.1 limits.cpp
1 程序清单 3.1
-
limits.cpp
// limits.cpp -- some integer limits #include <iostream> #include <climits> // use limits.h for older systems int main() { using namespace std; int n_int = INT_MAX; // initialize n_int to max int value short n_short = SHRT_MAX; // symbols defined in climits file long n_long = LONG_MAX; long long n_llong = LLONG_MAX; // sizeof operator yields size of type or of variable cout << "int is " << sizeof(int) << " bytes." << endl; cout << "short is " << sizeof n_short << " bytes." << endl; cout << "long is " << sizeof n_long << " bytes." << endl; cout << "long long is " << sizeof n_llong << " bytes." << endl; cout << endl; cout << "Maximum values:" << endl; cout << "int: " << n_int << endl; cout << "short: " << n_short << endl; cout << "long: " << n_long << endl; cout << "long long: " << n_llong << endl; cout << "Minimum int value = " << INT_MIN << endl; cout << "Bits per byte = " << CHAR_BIT << endl; cout << "char的位数[CHAR_BIT] : " << CHAR_BIT << endl; cout << "char的最大值[CHAR_MAX] : " << CHAR_MAX << endl; cout << "char的最小值[CHAR_MIN] : " << CHAR_MIN << endl; cout << "signed char 最大值[SCHAR_MAX] : " << SCHAR_MAX << endl; cout << "signed char 最小值[SCHAR_MIN] : " << SCHAR_MIN << endl; cout << "unsigned char 最大值[UCHAR_MAX] : " << UCHAR_MAX << endl; cout << "short 最大值[SHRT_MAX] : " << SHRT_MAX << endl; cout << "short 最小值[SHRT_MIN] : " << SHRT_MIN << endl; cout << "unsigned short 最大值[USHRT_MAX] : " << USHRT_MAX << endl; cout << "int 最大值[INT_MAX] : " << INT_MAX << endl; cout << "int 最小值[INT_MIN] : " << INT_MIN << endl; cout << "unsigned int 最大值[UINT_MAX] : " << UINT_MAX << endl; cout << "long 最大值[LONG_MAX] : " << LONG_MAX << endl; cout << "long 最小值[LONG_MIN] : " << LONG_MIN << endl; cout << "unsigned long 最大值[ULONG_MAX] : " << ULONG_MAX << endl; cout << "long long 最大值[LLONG_MAX] : " << LLONG_MAX << endl; cout << "long long 最小值[LLONG_MIN] : " << LLONG_MIN << endl; cout << "unsigned long long 最大值[ULLONG_MAX] : " << ULLONG_MAX << endl; return 0; }
-
运行结果
int is 4 bytes. short is 2 bytes. long is 4 bytes. long long is 8 bytes. Maximum values: int: 2147483647 short: 32767 long: 2147483647 long long: 9223372036854775807 Minimum int value = -2147483648 Bits per byte = 8 char的位数[CHAR_BIT] : 8 char的最大值[CHAR_MAX] : 127 char的最小值[CHAR_MIN] : -128 signed char 最大值[SCHAR_MAX] : 127 signed char 最小值[SCHAR_MIN] : -128 unsigned char 最大值[UCHAR_MAX] : 255 short 最大值[SHRT_MAX] : 32767 short 最小值[SHRT_MIN] : -32768 unsigned short 最大值[USHRT_MAX] : 65535 int 最大值[INT_MAX] : 2147483647 int 最小值[INT_MIN] : -2147483648 unsigned int 最大值[UINT_MAX] : 4294967295 long 最大值[LONG_MAX] : 2147483647 long 最小值[LONG_MIN] : -2147483648 unsigned long 最大值[ULONG_MAX] : 4294967295 long long 最大值[LLONG_MAX] : 9223372036854775807 long long 最小值[LLONG_MIN] : -9223372036854775808 unsigned long long 最大值[ULLONG_MAX] : 18446744073709551615
2 注意事项
- 如果您的系统不支持类型long long ,应删除使用该类型的代码行。
- 以上结果输出来自运行64位Windows7系统。
- 比源代码多部分内容。
这篇关于3.1 limits.cpp的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15PingCAP 黄东旭参与 CCF 秀湖会议,共探开源教育未来
- 2024-05-13PingCAP 戴涛:构建面向未来的金融核心系统
- 2024-05-09flutter3.x_macos桌面os实战
- 2024-05-09Rust中的并发性:Sync 和 Send Traits
- 2024-05-08使用Ollama和OpenWebUI在CPU上玩转Meta Llama3-8B
- 2024-05-08完工标准(DoD)与验收条件(AC)究竟有什么不同?
- 2024-05-084万 star 的 NocoDB 在 sealos 上一键起,轻松把数据库编程智能表格
- 2024-05-08Mac 版Stable Diffusion WebUI的安装
- 2024-05-08解锁CodeGeeX智能问答中3项独有的隐藏技能
- 2024-05-08RAG算法优化+新增代码仓库支持,CodeGeeX的@repo功能效果提升