C++ defines a set of primitive types that include the arithmetic types and a special type names void .

Arithmetic Types

all arithmetic types

C++: Arithmetic Types

C++: Arithmetic Types

Signed and Unsigned Types

The integral types and char have signed and unsigned types.

Advice: Deciding which Types to use

<aside> 💡 Deciding which Types to use

char Type in arithmetic expression

int main() {
  unsigned char num1 = 1;
  unsigned char num2 = 'a';     // 'a' is 97 is Ascii Table
  int num3 = 2;
  std::cout << num1 + num2 + num3 << std::endl; // print 100
  return 0;
}

Exercise

What are the differences between int, long , long long , and short ? Between an unsigned and a signed type? Between a float and a double ?

C++ guarantees short and int is at least 16 bits, long at least 32 bits, long long at least 64 bits.

The signed can represent positive numbers, negative numbers and zero, while unsigned can only represent numbers no less than zero.

The C and C++ standards do not specify the representation of float , double and long double. It is possible that all three implemented as IEEE double-precision. Nevertheless, for most architectures (gcc, MSVC; x86, x64, ARM) float is indeed a IEEE single-precision floating point number (binary32), and double is a IEEE double-precision floating point number (binary64).

Type Conversions