Common data types in C++

Common data types in C++

June 30, 2024·İbrahim Korucuoğlu
İbrahim Korucuoğlu

C++ supports several different data types. Here are some of the most common ones:

  • Integer types (int) : These are used to store whole numbers. The size of an int is usually 4 bytes (32 bits), and it can store numbers from -2,147,483,648 to 2,147,483,647.
  • Floating-point types (float, double) : These are used to store real numbers (numbers with fractional parts). A float typically occupies 4 bytes of memory, while a double occupies 8 bytes.
  • Character types (char) : These are used to store individual characters. A char occupies 1 byte of memory and can store any character in the ASCII table.
  • Boolean type (bool) : This type is used to store either true or false.
  • String type (std::string) : This is used to store sequences of characters, or strings. It’s not a built-in type, but is included in the C++ Standard Library.
  • Array types : These are used to store multiple values of the same type in a single variable.
  • Pointer types : These are used to store memory addresses.
  • User-defined types (classes, structs, unions, enums) : These allow users to define their own data types.

Each of these types has its own characteristics and uses, and understanding them is fundamental to programming in C++.

Last updated on