c++ primer note 2 basic built-in types

2-1 Note:

1. C++ only specifies the minimum size of each type of memory, and the number of bytes is at least long long >=long>=int>=short;

2. The character type is divided into char, signed char and unsigned char. The type char will actually appear as which of the above types, which is determined by the compiler; in VS2013, char == signed char;

suggestion:

1. When it is clearly known that the value cannot be negative, use the unsigned type;

2. char is only used to store characters, a small integer is required, signed char or unsinged char (clearly pointed out);

3. Use double for floating-point numbers (double uses 2 words (64 bits) to represent the precision);

 

2-2 Note:

1、非bool->bool,0->false , 非0->true;

2、bool->非bool,false->0,true->1;

3. When an unsigned type is assigned a value that exceeds the range it represents, the result is the remainder after the initial value is modulo the total number of values ​​represented by the unsigned type;

unsigned char = -1; (0~255); 

Actually -1%256 = 255; the remainder after modulo! https://blog.csdn.net/kkkkkkkkq/article/details/72235878

4. When we assign a value to a signed type that exceeds the range it represents, the result is undefined!

signed char c2 = 256; //Assuming char occupies 8 bits, the value of c2 is undefined.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325220021&siteId=291194637