How to use if statement in C?
The following examples demonstrate how to use the if statement in C:
C
// C Program to demonstrate the syntax of if statement #include <stdio.h> int main() { int gfg = 9; // if statement with true condition if (gfg < 10) { printf ( "%d is less than 10" , gfg); } // if statement with false condition if (gfg > 20) { printf ( "%d is greater than 20" , gfg); } return 0; } |
Output
9 is less than 10
C – if Statement
The if in C is the most simple decision-making statement. It consists of the test condition and if block or body. If the given condition is true only then the if block will be executed.