Articles added in Mathematics Lab | Cyber Lab is now open | Astronomy Lab is now open | VLSI Lab is now open | 120 SEO Tips article published | More exciting articles coming soon!

Statements in C++

An executable instruction is known as a statement. They can classified into two main categories:
  1. Simple statements or expression statements.
  2. Complex statements(Control statements: next chapter).

1) Expression Statements:

Any expression ending with a semi-colon (;) is known as an expression statement. For e.g.:
  • a=b;
  • A=5;
  • a=b+c;
  • a++;

Input statement:

'cin' is an object(variable) declared in 'iostream.h' header file that represents the standard input device i.e. keyboard. This variable together with >> (extraction operator here) can be used for reading the value of a variable from the keyboard.

cin>>variable_name; --> this is an expression.
cin>>variable_name; --> this is a statement known as input statement.

int a;
cin>>a; //to read value of a

General syntax:
cin>>variable1>> variable2>>...>> variable.


In C++ constants are classified into two categories:
1) Numeric constants:
2, 5, -45, 1.1245, 1.542e+4, etc.
2) Non-numeric constants:
  1. Character constants --> Any character within ' ' is a character constant.
  2. E.g.: 'A', 'b', '6', '+'.

  3. String constants --> Any sequence of characters within " " is known as a string.
  4. E.g.: "Hello world", "12+152".

Output statement:

'cout' is an object that represents the standard output device i.e. monitor. Using cout together with << (insertion operator here), we can display the value of a variable or a constant or an expression.
cout< This is an expression.
cout< This is a statement known as output statement.

  1. cout<<"hello";
    output --> hello

  2. cout<<"Hello";
    output --> HelloHello

  3. cout <<"Hello\n";

    Note -->'\n' is a special character constant known as new line character that brings the cursor to the next line.

  4. Let a=5, b=6
    cout << a;
    cout << b;
    output --> 56

  5. cout<<"Value of a= " << a;
    cout<<"Value of b= " << b;
    output --> Value of a= 5Value of b= 6

CACKLE comment system

Programming Resources
Computer Networking Fundamentals Android Application