number of bytes for a type in C++

C

Carl Muller

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top