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

来源:互联网 发布:zbrush 4r8 mac破解版 编辑:程序博客网 时间:2024/05/12 23:08
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 : 1the size of int : 4the size of double : 8the size of unsigned char : 1the size of signed char : 1the size of unsigned int : 4the size of signed int : 4the size of short int : 2the size of long int : 4the size of float : 4the size of long double : 8the size of bool : 1the size of char * : 4the size of int * : 4the size of double * : 4the size of void * : 4the size of bool * : 4smallest char == -128largest char == 127is the char singed ? 1smallest int == -2147483648largest int == 2147483647smallest double == 2.22507e-308largest double == 1.79769e+308smallest bool == 0largest bool == 1smallest short == -32768largest short == 32767smallest long == -2147483648largest long == 2147483647smallest float == 1.17549e-038largest float == 3.40282e+038smallest long double == 2.22507e-308largest long double == 1.79769e+308smallest unsigned char == 0largest unsigned char == 255smallest unsigned int == 0largest unsigned int == 4294967295smallest unsigned short == 0largest unsigned short == 65535smallest unsigned long == 0largest unsigned long == 4294967295注:为了使网页尽可能显示美观,我插入了很多空格。所以,如果你把上面的代码直接copy到vc6.0中运行,输出结果的排版可能不同(没这么整齐)。:)