Preview
If Statement in C Language
It is a very useful decision making statement and it is used to control or alter the flow of execution of C language statements in a C Program.
It is categorized into four types:
- Simple if statement
- If else Statement
- Nested if Statement
- If else if ladder Statement
Simple if statement in C language
Simple if statement contains only one condition and a set of statements will be executed depending upon the output of condition. The syntax of simple if statement is:
if(Condition-Expression)
{
Statements;
}
Condition-Expression is comparison expression. If condition evaluates to be true, then Statements will execute. otherwise Statements will not execute.
Statements refers to statements of C Language.
Program
#include<stdio.h>
int main()
{
int a=10;
if(a<0)
printf("number is -ve");
printf("\nEnd");
return 0;
}
Output
End
In the above program, a is 10. Condition a<0 is false so only printf(“\nEnd”) would be executed.
Best Books of Computer Science