C - If Statement



 c-if-statement

Learn C - C tutorial - C if statement - C examples - C programs

C If Statement - Definition and Usage

  • In C- Programming the if statement is a conditional branching statement that is if the condition is satisfied the respective block of code is executed.
C If Statement

C Syntax

if (condition satisfy) 
{ 
Statements are executed; 
}

Sample coding - If statement

#include<stdio.h>
#include<conio.h>
void main()
{
    int a=10,b=10;
    if (a == b)
    {
        printf("a and b are equal"); 
    }
    getch();
}
                    

C Code - Explanation

C Code - Explanation if statement
  1. Here we declare the variable a &b as “10” with its data type as integer.
  2. In this statement we check the value for the variable a&b which are equal or not, because if the condition is true the printf statement prints “a” and “b” are equal”..

Output :

If statement sample output
  1. Here the value of the variable “a & b” are equal so “if” condition will be satisfied and the output print statement will be displayed as “a and b are equal”.


View More Quick Examples


Related Searches to C If Statement