Variables are use to store values in mental memory. Suppose you want to use different values in your C++ program, firstly you have to store them. For this purpose variables are use.
For example: you want to store 5 in your mental memory then you want to store 15 at the same time. Then you use different variables to store your data.
- a = 5;
- b = 15;
Here a and b are variables. You can give a variable any name you want. In other words variable is the name of your stored data.
To use of variables in C++, you must assigns a data type to that variables. The syntax of declaring a variable is;
- Int a;
- Char b;
- Float num;
Here int, char and float are the data types that tells us what type of data is stored in variables.
After declaration, you need to initialize your variable. The syntax of initialization of variable is;
Types and description
- Void: Represents the absence of type.
- Int: Integer type could be signed or unsigned depending on the range of data stored. Signed types shows both positive and negative values but unsigned types shows only positive values.
- Long int: long integer.
- Float: It is use when data is in decimal form.
- Double: It is same as float, but it could be use when data is too long.
- Long double: Long double precision floating point number.
- Char: It is use when you want to store characters. For example you want to store name, grade etc.
- Bool: It has been introduced to store Boolean value, true or false.