Home  >  Article  >  How many bytes does int occupy?

How many bytes does int occupy?

清浅
清浅Original
2019-03-12 14:47:41161337browse

The number of bits of memory occupied by the data type is related to the number of bits of the operating system and the compiler. Generally, in the current mainstream compilers, the int type is 4 bytes in either 32-bit or 64-bit systems.

How many bytes does int occupy?

【Recommended course: C Language Tutorial

The compiler can choose the appropriate size based on its own hardware, but it needs to meet constraints: short and int types are at least 16 bits, long type is at least 32 bits, and the length of short type cannot exceed int type, and int type cannot exceed long type. . This means that the variable length of each type is determined by the compiler. In current mainstream compilers, the int type in 32-bit machines and 64-bit machines is generally 4 bytes (for example, GCC). The following lists the number of bytes occupied by each type of variable under the GCC compiler on 32-bit machines and 64-bit machines:

     C类型            32               64
    char             1                1
    short int             2                2
    int             4                4
    long int             4                8
    long long int             8                8
    char*             4                8
    float             4                4
    double             8         8
It should be noted that the pointer type stores the address of the variable pointed to, so a 32-bit machine only requires 32 bits, and 64bit machines require 64bit.

Summary: The number of bits a data type occupies in memory is actually related to the number of bits in the operating system and the compiler (the number of bits supported by different compilers may be different). Specifically, the number of bytes occupied by a certain data type The compiler needs to coordinate the number of bits in the operating system before allocating the memory size


The above is the detailed content of How many bytes does int occupy?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is IMAP?Next article:What is IMAP?