#include <stdio.h>
int main()
{
if(condition)
{
statement
statement
...
}
else if(condition)
{
statement
statement
...
}
else if(condition)
{
statement
statement
...
}
else
{
statement
statement
....
}
return 0;
}
Look at the code:
#include<stdio.h>
main(){
int i = 10;
if (1==5){
printf("if\n");
}
else if(i==7){
printf("else if\n");
}
else{
printf("else\n");
}
}
In this code else will be executed and else will be printed.
jenny its easy,,try to understand...consider the below program
#include<stdio.h> main() { int i = 10,j=2; if (i==j){ printf("equal"); } else if(i==7) { printf("i value 7"); } else{ printf("not equal"); } }
in first if condition, i=j is tested since it is false it goes to else if condition since it is also false it goes to last statement where it acts a default statement if above condtions are false..so no need to write the condition again...hope u understand..thanks