C - Compare int value in if statement

Description

Compare int value in if statement

Demo

#include <stdio.h> 

int main() /*from  w  w  w .j  a  v a  2  s .c om*/
{ 
   int a,b; //Line 5

   a = 6; 
   b = a - 2; 

   if( a > b) 
   { 
      printf("%d is greater than %d\n",a,b); 
   } 
   return(0); 
}

Result

Line 5 declares two integer variables: a and b.

The variables are assigned values in Lines 7 and 8, with the value of variable b being calculated to be 2 less than variable a.

Line 10 makes a comparison:

if( a > b) 

Related Topic