[转]C/C++中的基本类型和极大极小值

C/C++中的基本类型和极大极小值 不说什么了,看源代码和结果一目了然。:) /************************************************************************/ /* show some c++ constant */ /* author : smileonce */ /* date : 2004-11-07 */ /************************************************************************/ #include "stdafx.h" #include #include using namespace std; int main(int argc, char* argv[]) { cout << "the size of char : " << sizeof(char) << endl << "the size of int : " << sizeof(int) << endl << "the size of double : " << sizeof(double) << endl // << "the size of void : " << sizeof(void) << endl // sizeof(void) --> warning #70: incomplete type is not allowed // but the system print result, the size of void is 0 << "the size of unsigned char : " << sizeof(unsigned char) << endl << "the size of signed char : " << sizeof(signed char) << endl << "the size of unsigned int : " << sizeof(unsigned int) << endl << "the size of signed int : " << sizeof(signed int) << endl << "the size of short int : " << sizeof(short int) << endl << "the size of long int : " << sizeof(long int) << endl << "the size of float : " << sizeof(float) << endl << "the size of long double : " << sizeof(long double) << endl << "the size of bool : " << sizeof(bool) << endl; cout << "the size of char * : " << sizeof(char *) << endl << "the size of int * : " << sizeof(int *) << endl << "the size of double * : " << sizeof(double *) << endl << "the size of void * : " << sizeof(void *) << endl << "the size of bool * : " << sizeof(bool *) << endl; cout << "smallest char == " << (int)numeric_limits ::min() << endl << "largest char == " << (int)numeric_limits ::max() << endl << "is the char singed ? " << numeric_limits ::is_signed << endl << "smallest int == " << numeric_limits ::min() << endl << "largest int == " << numeric_limits ::max() << endl << "smallest double == " << numeric_limits ::min() << endl << "largest double == " << numeric_limits ::max() << endl << "smallest bool == " << numeric_limits ::min() << endl << "largest bool == " << numeric_limits ::max() << endl << "smallest short == " << numeric_limits ::min() << endl << "largest short == " << numeric_limits ::max() << endl << "smallest long == " << numeric_limits ::min() << endl << "largest long == " << numeric_limits ::max() << endl << "smallest float == " << numeric_limits ::min() << endl << "largest float == " << numeric_limits ::max() << endl << "smallest long double == " << numeric_limits ::min() << endl << "largest long double == " << numeric_limits ::max() << endl; cout << "smallest unsigned char == " << (unsigned int)numeric_limits ::min() << endl << "largest unsigned char == " << (unsigned int)numeric_limits ::max() << endl << "smallest unsigned int == " << numeric_limits ::min() << endl << "largest unsigned int == " << numeric_limits ::max() << endl << "smallest unsigned short == " << numeric_limits ::min() << endl << "largest unsigned short == " << numeric_limits ::max() << endl << "smallest unsigned long == " << numeric_limits ::min() << endl << "largest unsigned long == " << numeric_limits ::max() << endl; return 0; } 在windows 2000下,输出结果如下: the size of char : 1 the size of int : 4 the size of double : 8 the size of unsigned char : 1 the size of signed char : 1 the size of unsigned int : 4 the size of signed int : 4 the size of short int : 2 the size of long int : 4 the size of float : 4 the size of long double : 8 the size of bool : 1 the size of char * : 4 the size of int * : 4 the size of double * : 4 the size of void * : 4 the size of bool * : 4 smallest char == -128 largest char == 127 is the char singed ? 1 smallest int == -2147483648 largest int == 2147483647 smallest double == 2.22507e-308 largest double == 1.79769e+308 smallest bool == 0 largest bool == 1 smallest short == -32768 largest short == 32767 smallest long == -2147483648 largest long == 2147483647 smallest float == 1.17549e-038 largest float == 3.40282e+038 smallest long double == 2.22507e-308 largest long double == 1.79769e+308 smallest unsigned char == 0 largest unsigned char == 255 smallest unsigned int == 0 largest unsigned int == 4294967295 smallest unsigned short == 0 largest unsigned short == 65535 smallest unsigned long == 0 largest unsigned long == 4294967295 注:为了使网页尽可能显示美观,我插入了很多空格。所以,如果你把上面的代码直接copy到vc6.0中运行,输出结果的排版可能不同(没这么整齐)。:)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值