Variables in C++ Programing Language

 Variables in C++ Programing Language 

Definition:

  1. It is a name of storage space that is used to store data.
  2. Its value is changeable.
  3. It always contains the last value stored in it.
  4. 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.
  1. Local Variables
  2. Global Variable
  3. Static Variables
  4. Automatic Variables
  5. External Variables.

Rules to declare a variable:

  1. The first letter of the variable should be the alphabet or underscore (_).
  2. The first letter of the variable should not be a digit.
  3. After the first character it may be a combination of alphabets and digits.
  4. Blank spaces are not allowed in a variable name.
  5. 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

Popular posts from this blog

What is Programming.