Variable in C++

A variable is a name of memory area. It is utilized to store data. Its worth can be changed and it tends to be reused commonly.

C++ variable


It is a method for addressing memory location through symbol so that it tends to be effectively identified.

We should see the syntax to declare a variable:


type variable_list;   

The case of declaring variable is given beneath:
int x;    

float y;    

char z;    

Here, x, y, z are variables and int, float, char are data types.

We can likewise provide values while pronouncing the variables as given below:

int x=5,b=10;  //declaring 2 variable of integer type    

float f=30.8;    

char c='A';    

Rules for naming a variable in C++ :

  • A variable name can just have alphabets, numbers, and the underscore _.
  • A variable name can't begin with a number.
  • Variable names ought not start with an capitalized character.
  • A variable name can't be a keyword. For example, int is a keyword that is utilized to denote integers.
  • A variable name can begin with an underscore. Nonetheless, it's not considered a good practice.


Previous                                                                             Next