Thursday, 22 March 2018


"A variables is a temporary container to store information , it is a named location in computer memory where varying data like numbers and characters can be stored and manipulated during the execution of the program".
A variable must be declared before it is used.It is a must because the compiler wants to be aware of it.

Types of Variables

Basically there are two types of variables , namely
 1. local Variable
 2. Global Variable

Local Variable 
  The local variable is created when the functions gets control and is destroyed when the control transfers back to the caller.

Global Variable
  Whereas the Global Variable is known and accessible throughout program.Global Variables are declared at the top of the module.

Declaration of Variable
  The declaration of a variable is simple in C++ language.It begins with the data type, followed by at least a space, followed by the name of a variable with a semicolon. Space is optional before the semicolon.

For Example

  int my_Age;
  int my_Salary;

If different variable are using the same data type on the same line are also allowed,but care must be taken to separate two with a comma except the last one that would end with a semicolon.

Initialization of variables

   When the variables in the example above are declared, they have an undetermined value until they are assigned a value for the first time.But it is possible for a variable to have a specific value from the moment it is declared.This is called the initialization of the variable.
      type identifier = initial_value;
For example, to declare a variable of type int called x and initialize it to a value of zero from the same moment it is declared,we can write:
     int x = 0;


Post a comment

Popular Posts


Android (21) AngularJS (1) Assembly Language (2) Books (10) C (75) C# (4) C++ (81) Data Strucures (4) Downloads (1) Engineering (13) FPL (17) Hadoop (1) HTML&CSS (38) IS (25) Java (87) Leet Code (4) PHP (20) Python (214) R (69) Selenium Webdriver (2) Software (14) SQL (27)