Conditional operators used in C. - C Operator

C examples for Operator:Conditional Operator

Introduction

Operator Description
==Equal (two equal signs)
!= Not equal
> Greater than
< Less than
>=Greater than or equal to
<=Less than or equal to

Example usage.

Expression Result
5 == 5 True
5 != 5 False
5 > 5 False
5 < 5 False
5 >= 5 True
5 <= 5 True

Demo Code

#include <stdio.h> 
int main() { //from  w  w  w . ja  v a2s  . co  m
   int iResponse = 0; 

   printf("\n1\tTurn the AC on\n"); 
   printf("2\tTurn the AC off\n"); 
   printf("\nEnter your selection: "); 
   scanf("%d", &iResponse); 

   if (iResponse == 1) {
      printf("\nAC is now on\n"); 
   }
   if (iResponse == 2){ 
      printf("\nAC is now off\n"); 
   }
}

Result


Related Tutorials