Rules For Declaring Variable
- The name of the variable contains letters, digits, and underscores.
- The name of the variable is case sensitive (ex Arr and arr both are different variables).
- The name of the variable does not contain any whitespace and special characters (ex #,$,%,*, etc).
- All the variable names must begin with a letter of the alphabet or an underscore(_).
- We cannot used C++ keyword(ex float,double,class)as a variable name.
Valid variable names:
int x; //can be letters int _yz; //can be underscores int z40;//can be letters
Invalid variable names:
int 89; Should not be a number int a b; //Should not contain any whitespace int double;// C++ keyword CAN NOT BE USED
C++ Variables
Variables in C++ is a name given to a memory location. It is the basic unit of storage in a program.
- The value stored in a variable can be changed during program execution.
- A variable is only a name given to a memory location, all the operations done on the variable effects that memory location.
- In C++, all the variables must be declared before use.
Contact Us