

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain if-else statement in C language
If-else statement takes care of true as well as false conditions. ‘true block’ is executed, when the condition is true and ‘false block’ (or) ‘else block’ is executed, when the condition is false.
Syntax
Refer the syntax given below −
if (condition){ True block statement(s) }else{ False block statement(s) }
Working of ifelse statement
In if else condition, if condition is true, it enter into true block statements, execute the operation and exits from the block.
If condition is false, it enter into else block, which is false block based on if condition, executes that else block and exist that else block.
Example
Following is the C program to execute If and If Else conditional operators −
#include<stdio.h> void main (){ int a=4; printf("Enter the value of a: \n"); scanf("%d",&a); if(a%2==1){ printf("a is odd number \n"); }else{ printf("a is even number"); } }
Output
You will see the following output −
Run 1: Enter the value of a: 26 a is even number Run 2: Enter the value of a: 53 a is odd number
- Related Questions & Answers
- Explain Nested if-else statement in C language
- Explain else-if ladder statement in C language
- Explain ‘simple if’ statement in C language
- Java if-else statement
- IF ELSE statement in a MySQL Statement?
- Explain switch statement in C language
- Java if-else-if ladder statement
- How to use ‘else if ladder’ conditional statement is C language?
- Java if-then-else statement
- What is if...else if... statement in JavaScript?
- Explain Try, Except and Else statement in Python.
- What is the if...else statement in JavaScript?
- How to indent an if...else statement in Python?
- What is the ‘if...else if...else’ statement in Java and how to use it?
- What is basic syntax of Python if...else statement?
Advertisements