C - If Else Statement

if-else selects between two alternative blocks.

Learning Objectives

  • Write if-else branches for binary choices.

Prerequisites

Example

#include <stdio.h>

int main(void) {
    int score = 72;
    if (score >= 60) {
        printf("pass\n");
    } else {
        printf("fail\n");
    }
}

Common Pitfalls

  • Chained if-else can be harder to read than switch when matching constants.

Checks for Understanding

  1. What prints when score is 59?
Show answers
  1. fail