• Call Us: +91 9437911966
  • Email Us: info@studentstutorial.com
  • Home
  • C Examples
  • Server Side
    • PHP
    • Java
    • CodeIgniter
    • Laravel
    • JSP
    • JDBC
  • Frontend
    • HTML
    • CSS
    • Javascript
    • jQuery
    • AJAX
    • FPDF
    • TCPDF
  • APP & DB
    • Android
    • Cordova
    • SQL
    • Oracle
  • Project
C Tutorial C Introduction C Characteristic C Comments C Operator C Assign Operator C Arithmetic Oper.. C Logical Operator C Modulus Operator C Variable C Initialise Variable C Print F C Translators C Programming C Control Flow C If Else Statement C Nested If Else C Loops C While Loops C For Loops C Do While C Nested Loops

C If-else statement

  • Students Tutorial
  • 08 jun 2020
   

The if else statements are used to write code, based on some conditions.

If condition is true then block of code is executed if condition is false then corresponding block of code will be ignored.

Using else is always optional, it is recommended to use it when we have alternate blocks.

when we are working with it and else, only one block can be executed i.e. when ‘if’ condition false then only ’else’ past is executed.

Syntax if statement:

If (condition) {                                        
  Statement 1;
  Statement 2;
   _ _
   _ _
}
Syntax if..else statement:
If (condition) {                                        
  Statement 1;
  Statement 2;
   _ _
   _ _
}
Else{
Statement 1;
  Statement 2;
   _ _
   _ _

}


Example:

Suppose in an exam the passmark is 30 and you got 30 marks or above 30 then you will pass else you fail.

Syntax if statement:

#include <stdio.h>
int main () {

   /* local variable definition */
   int passmark = 30;
   int yourmark= 27;
 
   /* change the yourmark value to see see different result */
	
   if( passmark <=yourmark) {
      /* if condition is true then print the following */
      printf("You passed the exam !\n" );
   }
   else{
       printf("You are fail in the exam !\n" );
   }
   return 0;
}



Output: You passed the exam !

Student Tutorial is a online tutorial for web design and development. Here you can find easy example and explanation for each tutorial.
Copyright © 2016-2025 Student Tutorial

Server Side

  • PHP
  • Java
  • CodeIgniter
  • Laravel
  • JSP
  • JDBC

Frontend

  • HTML
  • CSS
  • Javascript
  • jQuery
  • AJAX
  • FPDF

App & Database

  • Android
  • Cordova
  • SQL
  • Oracle