Explain IF-Else Statement in C Language ?

  • If statement in C is known as a decision-making statement.
  • It makes a decision based on the condition given.
  • It is followed by an optional else statement.
  • The block of codes inside the if statement is executed only if the given condition is true.
  • Codes inside the curly braces are skipped if the condition evaluates to false, and the code after the if statements are executed.
  • Code inside parenthesis of the if statement is true, everything within the curly braces is executed.
  • If condition true evaluates to true, code runs the printf execution.

Syntax

if (testCondition) {
   // statements
}

Sample Code

#include <stdio.h>
#include <stdbool.h>

int main(void) {
    if(true) {
        printf("Statement is True!\n");
    }

    return 0;
}

Output

Statement is True.

if..else statements

  • In an ..else statement, code inside the brackets is executed only if the statement condition evaluates to true.
  • If the condition in the if statement evaluates to false, the code inside the else statement is executed.

 

Leave a Reply

Your email address will not be published.

You May Also Like