Conditional Statements Interview Questions

    Question 1C++ If Statement

    Which of the following is the correct syntax of an if statement in C++?

    Question 2C++ Guess the Output – Simple If

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { int x = 10; if (x > 5) cout << "Hello"; return 0; }

    Question 3C++ If-Else Statement

    Which keyword is used in C++ to specify an alternative block of code if the if condition is false?

    Question 4C++ Guess the Output – If-Else

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { int num = 8; if (num % 2 == 0) cout << "Even"; else cout << "Odd"; return 0; }

    Question 5C++ Else-If Ladder

    Which statement is true about an else-if ladder in C++?

    Question 6C++ Guess the Output – Else If Ladder

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { int marks = 75; if (marks > 90) cout << "Grade A"; else if (marks > 60) cout << "Grade B"; else cout << "Grade C"; return 0; }

    Question 7C++ Switch Statement

    Which of the following is NOT true about the switch statement in C++?

    Question 8C++ Guess the Output – Switch Case

    What will be the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { int day = 3; switch(day) { case 1: cout << "Monday"; break; case 2: cout << "Tuesday"; break; case 3: cout << "Wednesday"; break; default: cout << "Invalid"; } return 0; }

    Question 9C++ Nested If

    What is the output of the following C++ code snippet?

    #include <iostream> using namespace std; int main() { int x = 15; if (x > 10) { if (x < 20) cout << "Between 10 and 20"; else cout << "Greater than 20"; } return 0; }

    Question 10C++ Ternary Operator as If-Else

    Which of the following C++ statements correctly uses the ternary operator to check if a number n is even or odd?