### 1. 类型的大小

• A short integer is at least 16 bits wide.
• An int integer is at least as big as short.
• A long integer is at least 32 bits wide and at least as big as int.
• A long long integer is at least 64 bits wide and at least as big as long.

### 2. sizeof and climits

int days = 0
cout << "size of days is " << sizeof(days) << endl;
cout << "size of int is " << sizeof(int) << endl;

Results:
size of days is 4
size of int is 4

climits中定义了c++中基础类型的最大值，最小值，大小的常量值。
CHAR_BIT          Number of bits in a char
CHAR_MAX       Maximum char value
CHAR_MIN        Minimum char value
SCHAR_MAX    Maximum signed char value
SCHAR_MIN     Minimum signed char value
UCHAR_MAX   Maximum unsigned char value
SHRT_MAX       Maximum short value
SHRT_MIN        Minimum short value
USHRT_MAX    Maximum unsigned short value

climits的使用
#include <climits>
// use limits.h for older systems


### 3.  无符号类型

unsigned short change;
unsigned int rovert;
unsigned quarterback;  //unsigned int type
unsigned long gone;
unsigned long long lang_lang;

If signed integer max value is 32767. 32767 + 1, result is -32768.
If unsigned integer max value is 65535, if 65535 + 1, result is 0.

### 4. 类型转换。

• C++会自动将converts bool, char, unsigned char, signed char, and short values to int.
• The unsigned short type is converted to int if short is smaller than int. If the two types are the same size, unsigned short is con-
verted to unsigned int.
This rule ensures that there’s no data loss in promoting unsigned short.
• When an operation involves two types, the smaller is converted to the larger.

int a = 0;
double b = (double)a;

OR

double b = double(a);

double b = static_cast<double> (a);

#### C++基本数据类型及类型转换

2014-05-09 00:15:34

#### 输入3个整数，按有小到大的顺序输出（指针c++）

2016-12-10 16:51:39

#### C++ 隐式类类型转化 Implicit

2014-05-17 18:49:35

#### 跟我一起学C++之从C到C++（const限定符）

2016-06-05 11:36:15

#### Java自动类型转换和强制类型转换

2014-11-03 21:40:22

#### 输入三个数字，按从大到小输出 C语言代码

2017年10月20日 873B 下载

#### 【虚函数指针与虚函数列表】

2018-03-02 21:54:23

#### C++入门学习笔记

2016-11-10 08:40:53

#### C++选择排序法，按从大到小排序，long long 型

2014-07-17 07:25:50

#### c++11 各种类型转换

2016-09-17 16:49:29

## 不良信息举报

[C++]cpp小笔记3 --- C++基础类型的大小和转换