Variables are the folder of values in programming in general, they are based on saving the values inside them to be called when needed.
1.Types of variables
There are many types of variable in programming languages, but they share the same characteristics with a slight difference in the names. In C++, the main types of variables are:
- int: stores integers without decimals with a value of 4 bytes in memory.
- Double: It stores large numbers that contain decimals, and a large value is reserved in memory, up to 8 bytes.
- char: stores individual characters inside it and its size in memory is 1 byte.
- String: stores the text inside it and its size in memory is 1 byte/character.
- Boolean: It contains a value that is either true or false and its size in memory is 1 byte.
2.Uses
The uses of Variables are multiple, and they are, as we mentioned, the main portfolio for all program operator values. They cannot be abandoned within the program. They are the programming components themselves, and the other functions in the language that form, deal with their values, and update them constantly.
3. Example
Please, for a better understanding of Variable, copy the following code into your code editor.
int main() { int a = 0; char b = 'h'; bool c = false; double d = 1.4; float e = 1.5555; std::cout << "This is int : " << a << endl; std::cout << "This is char : " << b << endl; std::cout << "This is bool : " << c << endl; std::cout << "This is double : " << d << endl; std::cout << "This is float : " << e << endl; return 0; }