codegurukool.com · Free coding tutorials & online compiler

Home › C Tutorial › C if...else

C if...else

Choose between paths.

Use if, else if, else, or the short form cond ? a : b.

Example code

#include <stdio.h>
int main() {
  int t = 18;
  if (t < 12) printf("Morning\n");
  else if (t < 17) printf("Afternoon\n");
  else printf("Evening\n");
  return 0;
}

Run this code in the online editor

← C booleansC switch →