Simple if statement in C language

Preview

If Statement in C Language

If statement is a very powerful decision making statement and it is used to control the flow of execution of statements.

There are four types of if statement:

  • Simple if
  • If else
  • Nested if
  • If else if ladder



Simple if statement in C language

 In simple if statement, there is only one Condition and depending upon the Condition, a particular set of statements will be executed. The syntax of simple if statement is:

if(Condition)
{
StatementBlock;
}
Condition is comparison expression. If condition is true, only then StatementBlock will be executed. otherwise Statement-Block will not execute. Statement-Block  is a set of statements of C .

Program to demonstrate simple if
#include<stdio.h>
#include<conio.h>
main()
{
int a=10;
clrscr();
if(a<0)
printf(“number is -ve”);
printf(“\nBye”);
getch();
}
Output
Bye

In the above program, a is 10. 

Condition a<0 is false so only printf(“\nBye”) would be executed.



Lesson tags: if statement in c, simple if statement in c, types of if statement in c
Back to: C Programming Language