
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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:
"); scanf("%d",&a); if(a%2==1){ printf("a is odd number
"); }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 Articles
- Explain Nested if-else statement in C language
- Explain else-if ladder statement in C language
- Explain ‘simple if’ statement in C language
- How to use ‘else if ladder’ conditional statement is C language?
- Explain switch statement in C language
- IF ELSE statement in a MySQL Statement?
- Java if-else statement
- Java if-else-if ladder statement
- Java if-then-else statement
- Explain Try, Except and Else statement in Python.
- What is if...else if... statement in JavaScript?
- What is the if...else statement in JavaScript?
- What is the ‘if...else if...else’ statement in Java and how to use it?
- How to indent an if...else statement in Python?
- Explain the scope rules related to the statement blocks in C language

Advertisements