Variables in C++

Variables is a name given to memory location. 

            int x =10;                    

here, x is a integer variable.                                                    

Integer variable x is a name given to memory location and where we stored integer value10.

Initialize variable

we can also initialize variables as below.

int  a,b,c;


Here, we have initialized three integer variable a,b & c. variable  ‘a’  stores 10, variable ‘b’ stores 20 and variable ‘c’ stores 30.

Initialize multiple variable

we can also initialize multiple by comma separated list.

int a;             
char b;       
float c;

How to take input from user in C++

In C++ we can take a input from user by using “cin”.

In C++ , “cin” is an  object of class istream. 

“cin” object  is used to take the input from the standard input device i.e. keyboard.

In “cin” ,   “c” refers to “character” and ‘in’ means “input”, hence cin refers “character input”.

“cin” is used with the extraction operator (>>) for receive a stream of characters from user.

Syntax  of cin is:


How to take multiple input from user in C++

In C++ we can also take a multiple input at a time by using cin object.

Syntax to take multiple input at time by using cin.

cin >> Variable1 >> Variable2 >> … >> VariableN;



Categories C++