In this tutorial, we will learn about C if statement with some examples. The if statement is a two-way decision statement and is used with conditional expression.
C if Statement
The if statement is a decision-making statement and is used to control
the flow of execution of C program statements.
Let’s understand the basic syntax of the statement. The general syntax of the statement is as follows:
// block of program statements executed
// if the condition is true;
The block of statement is usually called the if-block and would be executed only if the condition or the conditional expression evaluates to true. If the condition is false the if-block will be omitted.
A simple C program to illustrate the usage of the if statement.
//declare a number
int number = 15;
//C if statement
if (number > 10)
In this example, the if block would be executed and the number would be printed on the console.
The variable number is declared and initialized with 15. Since, 15 > 10 the condition number > 10 would be true. Hence, the if block would be executed.
In the next tutorial, we will learn another variation of the statement. The if-else statement.
C Tutorials on this website can be found at: