Conditional Statements Interview Questions

    Question 1Purpose of if statement

    The primary purpose of an if statement in C programming is to:

    Question 2if-else if vs. separate if

    What is a key difference between using a series of separate if statements and using an if-else if ladder?

    Question 3Purpose of switch statement

    The switch statement is best suited for scenarios where you need to:

    Question 4The break keyword

    What is the main purpose of the break keyword inside a switch statement?

    Question 5The default case

    The default case in a switch statement serves what purpose?

    Question 6Simple If Statement

    What is the output of the following C code?

    #include int main() { int x = 10; if (x == 10) { printf("True"); } else { printf("False"); } return 0; }

    Question 7If-Else Statement

    What is the output of the following C code?

    #include int main() { int num = 7; if (num % 2 == 0) { printf("Even"); } else { printf("Odd"); } return 0; }

    Question 8Else-If Ladder

    What is the output of the following C code?

    #include int main() { int score = 85; if (score >= 90) { printf("A"); } else if (score >= 80) { printf("B"); } else { printf("C"); } return 0; }

    Question 9Nested If Statements

    What is the output of the following C code?

    #include int main() { int a = 5, b = 10; if (a < b) { if (a == 5) { printf("Correct"); } } else { printf("Incorrect"); } return 0; }

    Question 10Logical Operators in If

    What is the output of the following C code?

    #include int main() { int temp = 25; if (temp > 20 && temp < 30) { printf("Pleasant"); } else { printf("Extreme"); } return 0; }