Home >>C++ Tutorial >C++ Variable

C++ Variable

C++ Variable

Variable is used to store data.And also it is another name for the memory location. A variable can be reused several times as its value can be changed. In order to be identified easily, variables represent the memory location through symbol.

Here is the syntax of declaring the variables in C++

Datatype variable_name;

Examples for variable Declaration given below

int a;    
float b;       

Rules for defining the variables

Here are the rules that are used for declaring a variable in C++:

  • Alphabets, digits and underscore can be contained in the variables.
  • Please note that the name of the variable will start with alphabet and underscore only but it cannot start with the digit.
  • In the name of the variable there are no white spaces are allowed.
  • Point to be noted that the name of the variables should not contain any keyword or any reserved words.
  •  

Here is the example of the valid and invalid variables name:

Valid variable names:

int a;    
int _ab;    
int a30;    

Invalid variable names:

int 10;    
int @ab;    
int a 30;    

No Sidebar ads