Statements in C++

Instructions given to a computer to perform any kind of action are called statements in c++.  Statements in C++ are terminated with a semicolon (;) and they form the smallest executable unit in a c++ program.

1. What is a Simple Statement in C++

The simplest statement in c++ is a null or empty statement. It takes the following form :

;      // a null statement.

Why Null Statement in C++ ?

Null statement is useful in those instances, where the syntax of the language requires the presence of a statement but where the logic of the program does not.

Where Null statements are used ?

Generally in loops and their bodies

2. Compound Statement in C++

If the statements in C++ is a sequence of statements enclosed by a pair of braces {} , It is called compound statement.

Flow Control of Statements –

Flow Control- Statements in C++

1. Sequence –

As the name suggests, the statements are being executed sequentially.

Representation : 

sequence_structure (Statements in C++)

A simple C++program to represent a sequence construct –
int main()
     cout<<"Hello world\n";                             //statement 1
     cout<<"This program is the simplest one and\n";    //statement 2
     cout<<"It is printing the Hello world message. ";  //statement 3
Hello world
this program is the simplest one and
it is printing the Hello world message.

So, every program in C++ starts with execution of first statement of main(), the, executing each and every statement next to first statement, and finally ends with execution of lats statement as shown in above example. The sequence construct specifies the normal flow of control in a program.

2) Selection –

As the name suggests, some selected statements are executed depending on a condition test.If the condition evaluates to true, then set of statement(s) are executed, and if the condition evaluates to false, then another set of statement(s) may or may not be executed.

Representation :

selection construct (statements in C++)

Selection Construct is also called decision construct, as it helps in making decisions about which set of statements is to be executed.

More on Selection Construct – Click Here for Selection Statements

3. Iteration 

Iteration means Repetition. so, As the meaning suggests, Iteration construct means repetition of a set of statements depending upon a condition test. The statements are repeated again and again, till the condition is true. But once the condition false, the repetition stops.

Representation : 

iteration (statements in C++)

The iteration construct is also called looping construct.

Body of the Loop : The set of statements that are repeated again and again.
Exit condition or Test Condition :  The condition on which the execution or exit of the loop depends.

Necessities of a Loop – 

  1. Starting Point → Initialization
  2. Ending Point → Condition
  3. Re-initialization → Re-initialization
  4. Testing Point → Body of the Loop

More on Iteration Construct – Click Here for Iteration Statements

Previous Home Next
Type Conversion and Type Casting in C++(Day 10) If and Switch Statement in C++ (Selection Construct)


This article has 1 comment

Leave a Reply