Chinaunix首页 | 论坛 | 博客
  • 博客访问: 816770
  • 博文数量: 756
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 4980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:40
文章分类

全部博文(756)

文章存档

2011年(1)

2008年(755)

我的朋友

分类:

2008-10-13 16:14:44

不说什么了,看源代码和结果一目了然。:)


/************************************************************************/
/*  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<char>::min() << endl 
      << "largest  char      ==  " << (int)numeric_limits<char>::max() << endl   
      << "is the char singed ?   " << numeric_limits<char>::is_signed  << endl
      << "smallest int       ==  " << numeric_limits<int>::min()       << endl
      << "largest  int       ==  " << numeric_limits<int>::max()       << endl
      << "smallest double    ==  " << numeric_limits<double>::min()    << endl
      << "largest  double    ==  " << numeric_limits<double>::max()    << endl
      << "smallest bool      ==  " << numeric_limits<bool>::min()      << endl
      << "largest  bool      ==  " << numeric_limits<bool>::max()      << endl
      << "smallest short     ==  " << numeric_limits<short>::min()     << endl
      << "largest  short     ==  " << numeric_limits<short>::max()     << endl
      << "smallest long      ==  " << numeric_limits<long>::min()      << endl
      << "largest  long      ==  " << numeric_limits<long>::max()      << endl         
      << "smallest float     ==  " << numeric_limits<float>::min()     << endl
      << "largest  float     ==  " << numeric_limits<float>::max()     << endl
      << "smallest long double == " << numeric_limits<long double>::min()  << endl
      << "largest  long double == " << numeric_limits<long double>::max()  << endl;

 cout << "smallest unsigned char  == " << (unsigned int)numeric_limits<unsigned char>::min()  << endl 
      << "largest  unsigned char  == " << (unsigned int)numeric_limits<unsigned char>::max()  << endl
      << "smallest unsigned int   == " << numeric_limits<unsigned int>::min()   << endl 
      << "largest  unsigned int   == " << numeric_limits<unsigned int>::max()   << endl
      << "smallest unsigned short == " << numeric_limits<unsigned short>::min() << endl 
      << "largest  unsigned short == " << numeric_limits<unsigned short>::max() << endl
      << "smallest unsigned long  == " << numeric_limits<unsigned long>::min()  << endl 
      << "largest  unsigned long  == " << numeric_limits<unsigned long>::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中运行,输出结果的排版可能不同(没这么整齐)。:)


--------------------next---------------------

阅读(765) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~