Prashant | Fri, 26 Jun, 2020 | 150
Syntax of if statement in C/C++ programming language, this article contains syntax, examples and explanation about the if statement in C language.
Here, is the syntax of if statement in C or C++ programming language:
if(test_condition)
{
//statement(s);
}
If the value of test_condition is true (non zero value), statement(s) will be executed. There may one or more than one statement in the body of if statement.
Be sure, when you have to use curly braces or not?
Consider the given example:
#include <stdio.h>
int main()
{
int a=10;
int b=-10;
int c=0;
if(a==10)
printf("First condition is true\n");
if(b)
printf("Second condition is true\n");
if(c)
printf("Third condition is true\n");
return 0;
}
Output
First condition is true Second condition is true
In this program there are three conditions
if(a==10)
This test condition is true because the value of a is 10.
if(b)
This test condition is true because the value of b is -10 that is a non zero value.
if(c)
This test condition is not true because the value of c is 0.