14. Fundamental Control Structure Statements in C [Part-1]

Table of Contents
< All Topics
Print

14. Fundamental Control Structure Statements in C [Part-1]

Any real-life coding solution is almost impossible without decision making or control structures in programming. These decision making enable us to make program more actionable and determine the order in which the program’s instructions have to be executed and govern how control is transferred to various parts of the program. Control statements are classified into the following categories. Control statements in C enable us to determine the order in which the program’s instructions are executed and govern how control is transferred to various parts of the program. Control statements are classified into the following categories:

  1. Selection statements
  2. Iteration statements
  3. Jump statements.
c control statements

Decision Making in C Language

Decision making statements are also known as selection statements or branching statements. C programming language assumes anynon-zeroandnon-nullvalues astrue, and if it is eitherzeroornull, then it is assumed asfalsevalue. A snapshot of all available control /decision making statements is –

1) If statement as a control structure

Syntax: The syntax of an if( ) statement in C programming language is:
if(boolean_expression)

{ /* statement(s) will execute if the Boolean expression is true */
}
  • If the Boolean expression evaluates to true, the code block inside the if statement will be executed.
  • If the Boolean expression evaluates to false, the code block following the end of the if statement (after the closing curly brace) will be executed.
  • In the C programming language, any non-zero and non-null values are considered true, while zero or null values are considered false.
Flow Diagram:

2) if –else statement as a control structure

Flow Diagram:
Image 2

Once the Boolean condition is true then one set of statement block will undergo the execution, otherwise the false set o statement block will undergo the execution. Here in flowchart Statement-1 are being followed when condition is false, and Statement-2 is being followed when condition is true.

Syntax: The syntax of an if…else statement in C programming language is:
if(boolean_expression)

{ /* statement(s) will execute if the boolean expression is true */

}

else

{ /* statement(s) will execute if the boolean expression is false */

}

If the Boolean expression evaluates to true then the if block of code will be executed otherwise else block of code will be executed programming language assumes any non-zero and non-null values as true and if it is either zero or null then it is assumed as false value.

Example: Are you permit to cast your vote?
= 18) printf("\n You can cast your vote"); else printf("\n Oh! you have wait till your age get 18"); }" style="color:#f6f6f4;display:none" aria-label="Copy" class="code-block-pro-copy-button">
// Example of If...else :
// Program to permit to cast vote if your age is 18 or more,
// otherwise give message to wait till 18.
#include<stdio.h>
 void main()
 {
 int age;
 printf("\n Kindly share your age : ");
 scanf("%d",&age);
 
 // check age and give a message
 if (age >= 18)
 printf("\n You can cast your vote");
 else 
 printf("\n Oh! you have wait till your age get 18");
 }

In a next post you will find details about nested if…else, if…else if… else and switch statements.


Leave a comment