Word Count: 158
  • Post category:C++
  • Post last modified:2023-01-11

Reference

W3School – C++ Tutorial

Data Types

Data TypeSizeDescription
bool1 byteStores true or false values
char1 byteStores a single character/letter/number, or ASCII values. The character must be surrounded by single quotes
int2 or 4 bytesStores whole numbers, without decimals
float4 bytesStores fractional numbers, containing one or more decimals. Sufficient for storing 6-7 decimal digits
double8 bytesStores fractional numbers, containing one or more decimals. Sufficient for storing 15 decimal digits
stringvariesStores a sequence of characters (text). This is not a built-in type, but it behaves like one in its most basic usage. String values must be surrounded by double quotes.

A string in C++ is actually an object, which contain functions that can perform certain operations on strings. For example, you can also concatenate strings with the append() function. For examples: text.append(“hello”), text.length().
int myNum = 5;               // Integer (whole number)
float myFloatNum = 5.99;     // Floating point number
double myDoubleNum = 9.98;   // Floating point number
char myLetter = 'D';         // Character
bool myBoolean = true;       // Boolean
string myText = "Hello";     // String