Tutorials

C Tutorial

All Tutorials Learning Tools Login

C Tutorial · Chapter 10 of 16

C If Else

Make decisions with conditions.

An if statement runs a block only when a condition is true. else handles the false path.

Use this for pass/fail checks, validation, and simple classification.

If/else sample Try it Yourself »
#include <stdio.h>

int main(void) {
    int score;
    printf("Enter score: ");
    scanf("%d", &score);
    if (score >= 75) {
        printf("Passed\n");
    } else {
        printf("Failed\n");
    }
    return 0;
}

Classroom Tips

  • Use braces even for one-line blocks while learning.
  • Do not confuse = with ==.