Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Why does the int type in java account for 4 bytes, while the int type in C language accounts for 2 bytes? Doesn't the number of bytes in an integer value depend on the computer?
Why does the int type in java account for 4 bytes, while the int type in C language accounts for 2 bytes? Doesn't the number of bytes in an integer value depend on the computer?
In java, Int is always 4 bytes, but C is different.

16-bit c compiler, int is 2 bytes, 32 bits in 32-bit c compiler and 8 bytes in 64-bit c compiler. According to the C language, the int type is the most suitable (not the most suitable, but at least quite suitable) integer type for the target device (16-bit or 32-bit or 64-bit CPU machine, etc.). ), at least 2 bytes.

It depends not simply on the computer, but on how many bits the program is compiled into. The program compiled into 16 bits is basically 2 bytes, as mentioned above. Then a 16-bit program can also run on a 32-bit machine (for example, if you run a 16-bit dos program on a 32-bit winxp machine, although your machine is 32-bit, the 16-bit program thinks that int is 2 bytes).