C - Where to put the semicolon for if statement

Introduction

Consider the following code

Demo

#include <stdio.h> 

int main() //  w w  w  . j  av a  2  s  .  co m
{ 
     int a,b; 

     a = 5; 
     b = -3; 
     if(a==b); 
          printf("%d equals %d\n",a,b); 
     return(0); 
}

Result

The trailing semicolon after if statement tells the program that the if statement has nothing to do when the condition is true.

That's because a single semicolon is a complete statement in C, albeit a null statement.

if(condition) 
      ; 

Related Topic