In C++ variable is used to store data in memory location, which can be modified or used in program during program execution.
There is some rules must be in your knowledge to work with C++ variables.
Rules of Declaring variables in C++
- Variable name can consist of Capital letters A-Z, lowercase letters a-z, digits 0-9, and the underscore character.
- The first character must be a letter or underscore.
- Blank spaces cannot be used in variable names.
- Special characters like #, $ are not allowed.
- C++ keywords can not be used as variable names.
- Variable names are case sensitive.
- A variable name can be consist of 31 characters only if we declare a variable more than 1 characters compiler will ignore after 31 characters.
- Variable type can be bool, char, int, float, double, void or wchar_t.
Variable Definition in C++
type variable_name, variable_name, variable_name;
/* variable definition and initialization */ int width, height=5; char letter='A'; float age, area; double d; /* actual initialization */ width = 10; age = 26.5;