Home Show/Hide Menu
C Tutorials
➜ C Language
  - Features of C
  - First C Program
  - Compilation in C
  - C Character Set
  - Tokens
  - Keywords
  - Identifiers
  - Constants
  - Operators
  - Data Types
  - Variables
  - Type Casting
  - Comments
  - Input/Output
  - Escape Sequence
  - Programming Errors
➜ Control Statements
  - if Statement
  - if-else Statement
  - Nested if-else
  - else-if
  - switch Statement
  - Loop
  - while loop
  - do while loop
  - for loop
  - break
  - continue & goto
  - Nested Loop
  - Infinite Loop
➜ Functions
  - What is function
  - Call by Value & Reference
  - Recursive function
  - Storage Classes
➜ Array
  - 1-D Array
  - 2-D Array
  - Return an Array
  - Array to Function
➜ C Pointers
  - Pointers
  - Pointer to Pointer
  - Pointer Arithmetic
  - Dangling Pointers
  - sizeof() operator
  - const Pointer
  - void pointer
  - Dereference Pointer
  - Null Pointer
  - Function Pointer
  - Function pointer as argument
➜ Memory Management
  - Memory Layout of C
  - Dynamic memory
  - calloc()
  - malloc()
  - realloc()
  - free()
➜ Strings
  - gets() & puts()
  - String Functions
  - strlen()
  - strcpy()
  - strcat()
  - strcmp()
  - strrev()
  - strlwr()
  - strupr()
  - strstr()
➜ C Math
  - Math Functions
➜ Enum, Structure & Union
  - Enum
  - Structure
  - typedef
  - Array of Structures
  - Nested Structure
  - Structure Padding
  - Union
➜ File Handling
  - fprintf() fscanf()
  - fputc() fgetc()
  - fputs() fgets()
  - fseek()
  - EOF and feof()
  - fsetpos()
  - tmpfile()
  - rewind()
  - ftell()
  - lseek()
➜ Preprocessor
  - Preprocessor
  - Macros
  - #include
  - #define
  - #undef
  - #ifdef
  - #ifndef
  - #if
  - #else
  - #error
  - #pragma
➜ Command Line
  - Arguments

else..if Statement in C Language

The else..if statement is an extension to the if-else statement and it is useful when programmers check multiple cases for different conditions within the program, nesting of if-else blocks can be avoided using else..if statement. It is similar to the switch case statement where a if or else-if condition is true then the statements defined in the if block will be executed, otherwise the default is executed instead of else block if none of the cases is matched. The syntax for nested if-else statement is as follows:-

    if(condition 1)
    {
        //when if condition 1 evaluates result as true
    }
    else if(condition 2)
    {
        Statements ;    //when if condition 2 evaluates result as true
    }
    else if(condition 3)
    {
        Statements ;    //when if condition 3 evaluates result as true
    }
    ...
    else if(condition N)
    {
        Statements ;    //when if condition N evaluates result as true
    }
    else
    {
        Statements ;    //when all if evaluate result as false
    }

#include<stdio.h>
#include<conio.h>
void main()
{
	int no1, no2;
	printf("Enter Number 1 : ");
	scanf("%d",&no1);
	printf("Enter Number 2 : ");
	scanf("%d",&no2);
	if(no1!=no2)
	{
		printf("Number 1 is not equal to Number 2");
	}
	else if(no1>no2)
	{
		printf("Number 1 is greater than Number 2");
	}
	else if(no1<no2)
	{
		printf("Number 1 is smaller than Number 2");
	}
	else
	{
		printf("Number 1 is equal to Number 2");
	}
	getch();
}

Flow Chart of else...if Statement

ADVERTISEMENT