Is the size of C “int” 2 bytes or 4 bytes?

后端 未结 13 2493
不知归路
不知归路 2020-11-22 10:52

Does an Integer variable in C occupy 2 bytes or 4 bytes? What are the factors that it depends on?

Most of the textbooks say integer variables occupy 2 bytes. But whe

相关标签:
13条回答
  • 2020-11-22 11:19

    I know it's equal to sizeof(int). The size of an int is really compiler dependent. Back in the day, when processors were 16 bit, an int was 2 bytes. Nowadays, it's most often 4 bytes on a 32-bit as well as 64-bit systems.

    Still, using sizeof(int) is the best way to get the size of an integer for the specific system the program is executed on.

    EDIT: Fixed wrong statement that int is 8 bytes on most 64-bit systems. For example, it is 4 bytes on 64-bit GCC.

    0 讨论(0)
提交回复
热议问题