Get to Know about Decision Making and branching Statements in Detail: C Language

INTRODUCTION:

A statement (also known as instruction) is the smallest element of any programming language. A statement or instruction is used to inform the computer to perform an action, when a program is executed. A statement can be used to set values of variables, alter the values of a variables, accept the input, manipulate the data and display the data. Each statement in C language must be terminated by a semicolon “;”.

The expression such as “a + b”, “c = 20”, “printf()” may become statements when they are terminated by a semicolon as shown below:


a + b;                 /* statement 1 */
c = 20;                /* statement 2 */
printf();            /* statement 3 */
 

A statement can be simple statement (discussed above) or can be compound statement. The set of statements enclosed within a pair of curly braces such as “{“and “}” is considered as a compound statement. For example, the following compound statement computes and display the sum of two values.
{
  Num1 = 15;                                   
  Num2 = 35;                                   
  Sum = Num1 + Num2;                           
  printf(“The sum of Num1 %d and Num2 %d = %d”,Num1,Num2,Sum);   
}
This compound statement can be treated as a single statement. Note that in a compound statement ‘}’ must not end with semicolon. So, all the operations like arithmetic, assignment, control structures and input/output function calls are considered as statements. Now, let us see “What are control statements? What are the types of the control statements?”

Sequential Statements with FlowChart and Example

0 comments:

Post a Comment