Variables are like containers for storing data values. In C++, there are different types of variables based on what type of data they hold.
To create a variable, you must specify the type and assign it a value:
type variableName = value;
Here are common variable types:
int: Stores integers (whole numbers), without decimals, such as 123 or -123.double: Stores floating point numbers, with decimals, such as 19.99 or -19.99.char: Stores single characters, such as 'a' or 'B'.string: Stores text, such as "Hello World".bool: Stores values with two states: true or false.#include <iostream> #include <string> using namespace std;int main() { int myNum = 15; double myFloatNum = 5.99; char myLetter = 'D'; string myText = "Hello"; bool myBoolean = true;
cout << myNum << "\n"; cout << myText << "\n"; return 0; }
Variable names must start with a letter or an underscore, and they are case-sensitive.
Which data type is used to store floating point numbers with decimals?