Some of the more popular primitive types in C++ are:
bool
: 1 byte (usually)int
: 4 byteschar
: 1 bytefloat
: 4 bytesdouble
: 8 bytesvoid
: no sizewchar_t
: 4 bytes
These data types generally have a fixed size, but they can be modified with keywords like short
, long
, signed
, and unsigned
, which affect the size of the type. C++ types are fairly extensible in this way, as opposed to, say, numbers in JavaScript, which would always be equivalent to the double
type above.
If a JS number value is used as a boolean (as in either 0
or 1
), you would think that only a single byte (or really just a single bit) would be needed to represent this integer, but JavaScript creates all numbers as an 8-byte double.
It's easy to see how this is a lot more flexible than numbers in JavaScript. In C++, we can declare a short int
, which will be 2 bytes.