number of bytes for a type in C++

Discussion in 'C++' started by Carl Muller, Dec 12, 2004.

  1. Carl Muller

    Carl Muller Guest

    >In C++, the amount of memory used to store int is 4 bytes,
    >or dependent upon the hardware?


    On the compiler/cpu I use, int uses 1 byte, but the byte has 16 bits
    so it can hold a value between -32768 and 32767.
    So sizeof(char) == sizeof(short) == sizeof(int) == 1 which is 16 bits,
    but sizeof(long) == 2 which is 32 bits.

    This is valid (but not common) for both the C and C++ standards.
    Carl Muller, Dec 12, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Collins
    Replies:
    3
    Views:
    5,993
    Jason Collins
    Feb 18, 2004
  2. Replies:
    6
    Views:
    415
    Rolf Magnus
    Dec 10, 2004
  3. mrby

    4-bytes or 8-bytes alignment?

    mrby, Nov 2, 2004, in forum: C Programming
    Replies:
    8
    Views:
    403
    Mark McIntyre
    Nov 2, 2004
  4. number of bytes for a type in C++

    , Dec 10, 2004, in forum: C Programming
    Replies:
    5
    Views:
    337
    Keith Thompson
    Dec 10, 2004
  5. Carl Muller

    number of bytes for a type in C++

    Carl Muller, Dec 12, 2004, in forum: C Programming
    Replies:
    3
    Views:
    334
    hari4063
    Dec 13, 2004
Loading...

Share This Page