(7) The difference in the number of bits occupied by each data type in 32/64-bit machines

  • The int type occupies 4 bytes in both 32-bit and 64-bit machines. The compiler can choose the appropriate size according to its own hardware, but it needs to meet the constraints: the short and int types are at least 16 bits, the long type is at least 32 bits, and the length of the short type cannot exceed the int type, and the int type cannot exceed the long type. This means that the length of each type of variable is determined by the compiler, and the current mainstream compilers are generally 32-bit machines and 64-bit machines. The int type is 4 bytes (for example, GCC). The following lists the number of bytes occupied by various types of variables for 32-bit machines and 64-bit machines under the GCC compiler:
 Type C 32nd place 64th Ranges
char 1 1 –128 ~ 127
short int 2 2 –32,768 ~ 32,767
int 4 4 Determined by the operating system, it is currently 4 bytes (32bit), which is -2,147,483,648 ~ 2,147,483,647 (10 digits)
long int 4 8 –2,147,483,648 ~ 2,147,483,647 (10 digits)
long long int 8 8 --9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (19 digits)
char*(pointer) 4 8 -
float 4 4 3.4E +/- 38 (7 digits)
double 8 8 1.7E +/- 308 (15 digits)

The pointer type stores the address of the variable pointed to, so a 32-bit machine only needs 32bit, and a 64-bit machine needs 64bit.

Guess you like

Origin blog.csdn.net/qq_40329851/article/details/114837662