Getting Started With C

Nested ifelse statements

Syntax:

if (condition1) {
// code block for condition1
if (condition2) {
// code block for condition2 inside condition1
} else {
// code block for else inside condition1
}
} else {
// code block for else outside condition1
}

Explanation:

Sample code:

Program.c

Output:

output.c

Resources :

Featured
Special title treatment

With supporting text below as a natural lead-in to additional content.

Q1. What is the output of C Program.?

                          int main()
                          {
                              if( 10 > 9 )
                                  printf("Singapore\n");
                              else if(4%2 == 0)
                                  printf("England\n");
                                  printf("Poland");
                              return 0;
                          }

Q2. Determine output:

                          int main() {
                              int p = 8, q = 10;
                          
                              if (p > q) {
                                  if (p < 15)
                                      printf("M");
                              } else {
                                  printf("N");
                              }
                          
                              return 0;
                          }
What will be the output of this code?