Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How many bytes does an int occupy?
How many bytes does an int occupy?
In C/C++ language, the number of bytes occupied by int and long int is related to the compiler.

But now most commonly used compilers think that int and long int are the same, which are 4 bytes, short is 2 bytes, and char is 1 byte.

If you only enter int, you can include the above three forms.

Different languages are different. For example, in Pascal, integer is 2 bytes, byte is 1 byte, and longint is 4 bytes.

It is recommended that you refer to the specific help of your compiler for more accurate information.

It's best to see how the current compiler defines it before using sizeof(int).

According to different compilers, the number of bytes defined by int is different. (The memory size occupied by data is different)

Commonly used single-chip compiler, such as KEIL, in the C language of 5 1 single-chip, int stands for 2 bytes (16 bits); If it is C language of 32-bit RAM processor, int stands for 4 bytes (32 bits).

In the C language of PIC bit series MCU, int stands for 16 bit.

Many compilers of PC-side software will define int as 8 bytes (64 bits) according to the operating system or processor (such as 64-bit XP).

So people who program on multiple platforms need to pay attention when using it.

If you need to define 16 digits, you can use short (short integer and short integer) definition.

Extended data:

In a general computer, int occupies 4 bytes and 32 bits, and the data range is-2147483648 ~ 2147483647 [-231~ 231].

In the previous microcomputer, int occupied 2 bytes, 16 bits, and the data range was-32768 ~ 32767 [-215 ~ 215-1].

Use printf to output the number of bytes occupied by int:

In addition to int types, there are short, long and long long types that can represent integers.

Unsigned int is an unsigned integer with the data range of [0 ~ 2 32-1].

Reference link: INT (data type) _ Baidu Encyclopedia