Statements in C++.


Introduction

Generally a program executes its statements from beginning to end. But not many programs execute all their statements in strict order from beginning to end. Most programs decide what to do in response to changing circumstances. These programs not only store data but they also manipulate data in terms of consolidation, rearranging, modifying data. To perform their manipulative miracles, programs need tools for performing repetitive actions and for making decision. C++ of course provides such tools by providing statements to attain so. Such statements are called program control statements. 


STATEMENTS

Statements are the instructions given to the computer to perform any kind of action, be it data movements, be it making decisions or be it repeating actions. Statements form the smallest executable unit within a C++ program. Statements are terminated with a semicolon (;). The simplest statements is the empty, or null statement. It takes the following form:

 ;                 //it is a null statement (notice, it is just a semicolon).

A 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. We will see it in loops and their bodies.

Compound Statement (Block)

A compound statement in C++ is a sequence of statements enclosed by a pair of braces {}. For instance,
            {
                 statement1;
                 statement2;
                 :             
                 :
}

represents a compound statement. A compound statement is equivalently called a block. A compound statement or a block is treated as a single unit and may appear anywhere in the program where a single statement may appear.

NOTE:- A compound statement in C++ is a sequence of statements enclosed by a pair of braces {} .


You may also like to visit:-
   STATEMENT FLOW CONTROL.

Post a Comment

0 Comments