Variables in C++


  • Variables are named locations in memory that are used to hold a value that may be modified by the program.

  • A variable may take different values at different times during execution.

Syntax for variable declaration :

DataType IdentifierName;

e.g. int a = 20;

Declaring,   Initializing,   and Assigning Variables:

int  number; //this is called declaration
We can also declare and assign some content to a variable at the same time, is called initialization.
int  number = 20; //this is called initialization
After declaring variables, you can assign a value to a variable later on using a statement like this:
num = 30; //this is called assignment
We can also assign a variable the value of another variable, like so:
num = num1;

Example :

int main()  //main function
    int x, y;     //declaration
    int z = 90;  //initialization
        x = z;  //assignment
    cout<<"Hello World!!\n";   
    return 0;

Next topic is variable-scope


Training For College Campus

We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.

Please mail your requirement at

Projects For Students

Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.

Students can mail requirement at

(8AM to 10PM):

+91-8527238801 , +91-9451396824

© 2017,, All rights reserved