size of int variable

18,780

It depends on the compiler.

For eg : Try an old turbo C compiler & it would give the size of 16 bits for an int because the word size (The size the processor could address with least effort) at the time of writing the compiler was 16.

Share:
18,780
Rohit
Author by

Rohit

Updated on June 04, 2022

Comments

  • Rohit
    Rohit almost 2 years

    How the size of int is decided?

    Is it true that the size of int will depend on the processor. For 32-bit machine, it will be 32 bits and for 16-bit it's 16.

    On my machine it's showing as 32 bits, although the machine has 64-bit processor and 64-bit Ubuntu installed.

  • Ed S.
    Ed S. over 11 years
    To be (extremely) pedantic; it would give 2 for sizeof int, and there are CHAR_BIT bits in a byte. sizeof returns the number of bytes, and there need not be 8 bits in a byte.
  • Rohit
    Rohit over 11 years
    thanx for the info, what's about on the 64 bit>Linux...in 64 bit systems the data bus will be of size 64 bits, there also the compiler is showing 4 bytes
  • pradipta
    pradipta over 11 years
    The concept is,in a 64 bit machine the compiler can support upto 8-byte data that doesn't mean it can't support 4 byte.Simply speaking lower system can compatible with the higher systems so,the system is 64-bit but the compiler is supporting upto 32-bit.so it is showing 4-byte,check for the latest compiler version.