Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Input/Output statements
  5. Decision making statement...
  6. if statement

if statement

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

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments