Table of Contents
show
if statement
syntax
if(expression)
{
Statement 1
Statement 2
}
Statement n
Flowchart
- An if statement consists of an if header and if body
- An if header consists of an if clause followed by an if controlling expression enclosed within parentheses
An if statement is executed as follows
- The if controlling expression is evaluated
- If the controlling expression evaluates to true, the statement constituting the if body is executed
- If the if controlling expression evaluates to false, then the statements present outside if will be executed
Example
#include<stdio.h>
int main()
{
int age;
printf("Enter the age: ");
scanf("%d",&age);
if(age >= 18)
{
printf("The person is eligible to vote");
}
return 0;
}
Output
Enter the age: 19
The person is eligible to vote
Views: 0