Last active
November 22, 2018 19:18
-
-
Save dbc2201/984527bdc655973522e344d3b16f7919 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) | |
{ | |
int a = 5; | |
if ( a > 10 ) | |
{ | |
printf("This was printed from inside if\n"); | |
} | |
else | |
{ | |
printf("This was printed from inside else\n"); | |
} | |
return 0; | |
} | |
//In the above program, the `else` block will be executed because the test condition ` a > 10 ` since the value of | |
//`a` is `5`, the condition results in a zero value representing the condition failed. | |
//But, in the case of an `if-else` block being written, such as | |
#include <stdio.h> | |
int main(void) | |
{ | |
int a = 5; | |
if ( a > 10 ) | |
{ | |
printf("This was printed from inside if\n"); | |
} | |
else if ( a % 2 != 0 ) | |
{ | |
printf("This was printed from inside else\n"); | |
} | |
return 0; | |
} | |
//In the above program, until the `if` after the else, the execution of the program is exactly same as the previous program. | |
//The only difference lies when the `else` block is about to be executed, another condition is tested, because we | |
//have now added an `if` to it. So this else will only execute if the `if` statement succeeding it is also true. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment