VOOZH about

URL: https://www.geeksforgeeks.org/c/c-if-else-statement/

⇱ C if else Statement - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C if else Statement

Last Updated : 18 Oct, 2025

The if else in C is an extension of the if statement which not only allows the program to execute one block of code if a condition is true, but also a different block if the condition is false.

  • If the condition is true, then the code inside the if block is executed, otherwise the code inside the else block is executed.
  • Any non-zero and non-null values are assumed to be true, and zero or null values are assumed to be false.

Output
10 is greater than 5

Explanation: In the above program, the condition checks if the variable n is greater than 5. If true, if block is executed and it prints that n is greater than 5. If it evaluates to false, the else block is executed, printing that n is less than 5. Since n is 10, it prints "10 is greater than 5".

Working of if-else statement

The below flowchart explains the if else works in C:

👁 flowchart of if-else statement in C
Flowchart of if-else in C
  • The if-else statement works by checking the condition defined with the if statement.
  • If the condition defined in the if statement is true, then the code inside the if block is executed and the rest is skipped.
  • If the condition evaluates to false, then the program executes the code in the else block

Negative Number check using If-else statement


Output
Negative

Explanation: In this program, the if statements check if the given number n is less than 0 which means that the number is negative. As n is negative, it prints the if block. But if the number n was positive, the else block would have been executed.

Note: If long at the block only contains the single statement, we can skip the curly braces.

Check if Integer Lies in the Range

Largest Among Three Numbers Using If-else


Output
11
Comment
Article Tags:
Article Tags: