CodersEditor Tutorials

CodersEditor Tutorials

  • Online IDE
  • Q&A
  • C Programming
  • Java
  • GraphQL.NET
  • System Software

›Control Flow/Decision Making

C Programming

    Introduction

    • Overview
    • Installation & Setup
    • C Program Structure
    • Keywords & Identifiers
    • Data Types
    • Variables & Constants
    • Scope Rules
    • Storage Class
    • Standard Input and Output
    • Operators

    Control Flow/Decision Making

    • Overview
    • if Statement
    • if else Statement
    • Nested If statement
    • Switch Statement
    • Nested Switch Statement
    • Conditional Operators

    Loop

    • Loops Overview
    • While loop
    • For Loop
    • Do while
    • Nested Loops
    • Break
    • Continue Statement
    • Goto statement

    Arrays

    • Arrays
    • Multi Dimensional Arrays
    • Arrays & Functions

    Pointers

    • Pointers Basics
    • Pointers and Arrays
    • Pointers and Functions
    • Memory allocation

    Strings

    • String Basics
    • String Functions

    C Programming Examples

    • Basic Example 1

if-else statement in C Programming

This article is about the if-else statement in C and its usage in the program.

If-else statement in C

The if statement followed by an additional else statement is known as the if-else statement. If-else statement is used in a condition where two operations have to be performed. If the condition is True it executes the if statement and if the condition returns False it executes the else statement.

Syntax

if (boolean expression)
{
  /statements executes if the expression is true 
}
else
{
  /statements executes if the expression is false
} 

Example

#include <stdio.h>
int main()
{
    int a;
    printf("Enter age: \n ");
    scanf("%d", &a);
    if (a >=18)
    {
        printf("eligible to vote");
    }
    else
        printf("not eligible to vote");
    
    return 0;
}

Output

Enter age: 16
not eligible to vote

In the above example, it checks for the value ’a’ if it is greater than or equal to 18 then it executes the statements inside the ‘if’ block and if it is lesser than 18 then it skips the 'if' block and executes the ‘else’ block alone. The if-else statement cannot execute both the if and else blocks simultaneously.

← if StatementNested If statement →
  • If-else statement in C
CodersEditor Tutorials
CoderdEditor Developer Tools
CodersEditor Online EditorGit Flavoured Markup EditorFree Online JSON FormatterFind My IP Address Details
Tutorials
C ProgrammingJava
Copyright © 2021 CodersEditor.com