Loading...
C++

Variables of C++

A variable is the name of a memory location. It is used to allocate memory to store the given data. Its values can be changed and it can be reused many times. It is a way to represent memory location through symbol so that it can be easily identified.

Declaring a Variable :

Syntax: Datatype variable_list;

Example:
int a;
float b;
char c;
Here, a,b,c are variables and int, float and char are datatype.

Initializing a Variable:

Syntax: Datatype variable=value;

Example:
int a=2;
float b=5.5;
char c=’X’;

Rules To Define Variables:
⦁ A variable can be any alphabet, digit and underscore.
⦁ A variable name should only start with alphabets and underscore but not with digit.
⦁ No spaces are allowed with in the variable name.
⦁ Variable name cannot be any reserved word or keyword. For example:char, float, const, etc.

Valid Variable Names:
int a;
int _name;
int a1;

Invalid Variable Name:
int 1;
int a b;
int char;

Leave a Reply

Your email address will not be published. Required fields are marked *