Variables in C++ Programing Language
Variables in C++ Programing Language
Definition:
- It is a name of storage space that is used to store data.
- Its value is changeable.
- It always contains the last value stored in it.
- It is always declared with the data type.
Types of Variables in C++:
In C++ there are 5 types of variables.
let's discuss each variable with an example.
- Local Variables
- Global Variable
- Static Variables
- Automatic Variables
- External Variables.
Rules to declare a variable:
- The first letter of the variable should be the alphabet or underscore (_).
- The first letter of the variable should not be a digit.
- After the first character it may be a combination of alphabets and digits.
- Blank spaces are not allowed in a variable name.
- Variable name should not be a Keyword.
Variable Initialization
int rollno=201;
float narks=85.25;
char grade='A';
Here 201 is the value of rollno,85.6 is the value of marks and A is the value of grade.
The character value is always written in single quotes.
Other methods of Variable Initialization
int rollno;
float marks;
char grade;
rollno=201;
float=85.52;
char='A';
Comments
Post a Comment