type
type of integer
Why define different integer types?
Different integer types occupy different memory sizes and represent different data ranges.
The computer records data through the switching state of the transistor, usually 8 are compiled into a group, we call it a byte.
The switching state of the transistor can be represented by 0 or 1. If it is turned on, it is represented by 1, and if it is turned off, it is represented by 0. - This representation method we call the binary method.
Therefore, a byte, 8 transistors, can have 2 to the 8th power states, each state corresponds to a value, therefore, a byte can represent 256 values.
To represent a larger data range, more transistors are required. However, memory is very precious for computers, so when we know the value range of the data type, we can better choose the integer type and save memory.
Occupies bytes and value ranges
Then use the keyword sizeof in visual studio to measure
the size of sizeof=size+of=something—it can measure the size of bytes occupied by entities. The
size of bytes occupied by different integer types:
data range
A byte is composed of 8 transistors, and the state of the transistor becomes a bit .
Too many are not easy for us to understand, so we try to reduce the number of bits and start analyzing from 3 bits.
3 transistors, what range of values can be represented?
There is a range of values to the power of 2, starting at 0 and ending at 7.
Expressed by addition and subtraction:
add 3 and -3, that is, add 011+101:
use three-bit binary to store data, the highest bit 1 is discarded, leaving only 000
knowledge of complement
Two's Complement Notation: A binary notation in which addition is equivalent to subtraction.
An hour hand has 12 points, that is, its modulus is 12.
How to make the hour hand go back to 0 (12) points?
——Backward 5h
——Forward 7h
range of integer values
The highest bit is the sign bit, so it is 2 to the 7th power and 2 to the 15th power. . . .
If we have determined that it must be a positive number and do not want the highest bit to be used as a sign bit, then use the unsigned keyword to indicate that there is no sign bit, and the highest bit represents a value.
float, char
The integer placeholder is %d
The floating point placeholder is %f
The character placeholder is %c