Skip to content

Instantly share code, notes, and snippets.

@rpivo
Last active December 15, 2020 13:58
Show Gist options
  • Save rpivo/16f5eac3e3434bb3b7e0595060dcd746 to your computer and use it in GitHub Desktop.
Save rpivo/16f5eac3e3434bb3b7e0595060dcd746 to your computer and use it in GitHub Desktop.
Common Data Types in C++

Common Data Types in C++

Some of the more popular primitive types in C++ are:

  • bool: 1 byte (usually)
  • int: 4 bytes
  • char: 1 byte
  • float: 4 bytes
  • double: 8 bytes
  • void: no size
  • wchar_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment