3.1 - Decision Statement.


Back Button Home

3.1.1 - If and If Else Statment.


1. What is the purpose of an "if" statement in a program?
  • (A) To repeat a block of code multiple times
  • (B) To take a decision based on a condition
  • (C) To execute all lines of code in a program
  • (D) To store values in variables
Correct Answer: (B) To take a decision based on a condition
2. Which of the following is a correct syntax for an "if" statement?
  • (A) if condition { statement; }
  • (B) if (condition);
  • (C) if (condition) { statement; }
  • (D) if condition { statement }
Correct Answer: (C) if (condition) { statement; }
3. Which of the following is a valid relational operator used in decision statements?
  • (A) **
  • (B) =
  • (C) ==
  • (D) #
Correct Answer: (C) ==
4. What will happen if the condition in an "if" statement evaluates to false?
  • (A) The "if" block will execute
  • (B) The program will terminate
  • (C) The "else" block will execute (if it exists)
  • (D) The program will ignore all conditions
Correct Answer: (C) The "else" block will execute (if it exists)
5. Which logical operator is used to check if both conditions are true?
  • (A) ||
  • (B) &&
  • (C) !
  • (D) ==
Correct Answer: (B) &&
6. Which of the following is an example of an "if-else" statement?
  • (A) if (condition) { statement; } else { statement; }
  • (B) if (condition) else { statement; }
  • (C) if condition { statement; } else statement;
  • (D) if { statement; }
Correct Answer: (A) if (condition) { statement; } else { statement; }
7. What will the following code output if the user enters 150?
            #include
            
            void main() {
                int no;
                printf("enter a no");
                scanf("%d", &no);
                if(no > 100) {
                    printf("No is >100 ");
                    printf("\n %d", no);
                }
                printf("\n End of program");
            }
                
  • (A) No is >100 150
  • (B) End of program
  • (C) No is >100
  • (D) No output
Correct Answer: (A) No is >100 150
8. What is the output of the following code if the user enters 3?
            #include
            
            void main() {
                int no;
                printf("enter a no");
                scanf("%d", &no);
                if(no % 2 == 0) {
                    printf("No is Even ");
                } else {
                    printf("No is Odd ");
                }
                printf("\n End of program");
            }
                
  • (A) No is Even
  • (B) No is Odd
  • (C) No is Odd End of program
  • (D) No is Even End of program
Correct Answer: (C) No is Odd End of program
9. Which statement can be used to check multiple conditions in a decision-making process?
  • (A) if...else if...else
  • (B) for loop
  • (C) while loop
  • (D) switch statement
Correct Answer: (A) if...else if...else
10. In a decision statement, what is the purpose of the else block?
  • (A) To execute if the condition is true
  • (B) To execute if the condition is false
  • (C) To stop the program
  • (D) To loop through conditions
Correct Answer: (B) To execute if the condition is false
11. Which of the following is a logical operator used in decision statements?
  • (A) >=
  • (B) !=
  • (C) &&
  • (D) ==
Correct Answer: (C) &&
12. What is the significance of parentheses () in an "if" condition?
  • (A) They define the statements inside the block
  • (B) They contain the condition that will be evaluated
  • (C) They allow multiple statements inside the block
  • (D) They are used to terminate the statement
Correct Answer: (B) They contain the condition that will be evaluated
13. What keyword is used to introduce an alternative condition in decision-making statements?
  • (A) else
  • (B) endif
  • (C) elseif
  • (D) switch
Correct Answer: (A) else
14. Which relational operator checks if two values are not equal?
  • (A) !=
  • (B) ==
  • (C) <=
  • (D) >=
Correct Answer: (A) !=
15. What kind of decision-making structure allows for multiple "if" statements one after another?
  • (A) Nested if
  • (B) Else if ladder
  • (C) Simple if
  • (D) For loop
Correct Answer: (B) Else if ladder

3.1.2 - If Else, If Else Statement, and Nested if Statment.


16. What is the purpose of using multiple if conditions?
  • (A) To handle more than two conditions
  • (B) To handle only one condition
  • (C) To handle one loop
  • (D) To handle no conditions
Correct Answer: (A) To handle more than two conditions
17. Is there a limit on the number of if conditions in a multiple if structure?
  • (A) Yes, it is limited to 3
  • (B) No, there is no limit
  • (C) Yes, it is limited to 5
  • (D) It depends on the programming language
Correct Answer: (B) No, there is no limit
18. How many blocks of statements are executed in a multiple if structure?
  • (A) One block of statements
  • (B) All blocks of statements
  • (C) Two blocks of statements
  • (D) No block of statements
Correct Answer: (A) One block of statements
19. What happens if the first condition in an if-else if structure is true?
  • (A) All conditions are evaluated
  • (B) The rest of the conditions are ignored
  • (C) Only the else block is executed
  • (D) The program terminates
Correct Answer: (B) The rest of the conditions are ignored
20. In the following code, what will be the output if a = 5, b = 10, and c = 3?
        if(a > b && a > c)
            printf("a is Largest number");
        else if(b > a && b > c)
            printf("b is Largest number");
        else
            printf("c is Largest number");
    
  • (A) a is Largest number
  • (B) b is Largest number
  • (C) c is Largest number
  • (D) No output
Correct Answer: (B) b is Largest number
21. What is the meaning of "nested if" statements?
  • (A) One if block inside another if block
  • (B) Multiple if blocks in sequence
  • (C) An else block inside an if block
  • (D) A while loop inside an if block
Correct Answer: (A) One if block inside another if block
22. How many levels of nested if statements can you have?
  • (A) Only 2 levels
  • (B) Only 3 levels
  • (C) Unlimited levels
  • (D) Limited to 5 levels
Correct Answer: (C) Unlimited levels
23. In a nested if structure, what happens if the outer if condition is false?
  • (A) The inner if conditions are evaluated
  • (B) The inner if conditions are ignored
  • (C) All conditions are ignored
  • (D) The program crashes
Correct Answer: (B) The inner if conditions are ignored
24. What is the syntax of an else if block in C?
  • (A) else if (condition)
  • (B) if (condition) else
  • (C) elseif (condition)
  • (D) else { if (condition) }
Correct Answer: (A) else if (condition)
25. What is the output of the following code if x = 7 and y = 5?
   if(x > 10)
   {
       if(y < 5)
           printf("Nested if true");
       else
           printf("Outer if true, inner if false");
   }
   else
   {
       printf("Outer if false");
   }
  
  • (A) Nested if true
  • (B) Outer if true, inner if false
  • (C) Outer if false
  • (D) No output
Correct Answer: (C) Outer if false

3.1.3 - Switch, Break, Continue/ Nested Switch Statements


25. What is the function of the break keyword in C programming?
  • (A) To start a loop
  • (B) To give pause to the program
  • (C) To exit from a block like a switch or loop
  • (D) To skip an iteration
Correct Answer: (C) To exit from a block like a switch or loop
26. In which programming constructs can the break keyword be used?
  • (A) If block only
  • (B) Switch case, while loop, do loop, for loop
  • (C) Switch case only
  • (D) For loop only
Correct Answer: (B) Switch case, while loop, do loop, for loop
27. What happens when a break statement is executed within a loop or switch block?
  • (A) Control moves to the next iteration
  • (B) Control moves out of the block
  • (C) Control remains in the block
  • (D) Control goes to the start of the block
Correct Answer: (B) Control moves out of the block
28. What does the continue keyword do in a loop?
  • (A) Skips the rest of the statements and continues to the next iteration
  • (B) Terminates the loop
  • (C) Moves the control out of the loop
  • (D) Executes the loop only once
Correct Answer: (A) Skips the rest of the statements and continues to the next iteration
29. What will happen if the continue statement is executed inside a loop?
  • (A) Control will exit the loop
  • (B) Control will skip the rest of the statements and return to the beginning of the loop
  • (C) Control will pause the loop
  • (D) Control will stop the execution of the program
Correct Answer: (B) Control will skip the rest of the statements and return to the beginning of the loop
30. What is the syntax of the continue statement?
  • (A) continue()
  • (B) continue;
  • (C) continue{}
  • (D) break;
Correct Answer: (B) continue;
31. Which of the following keywords are used in a switch statement in C programming?
  • (A) switch, if, else
  • (B) switch, case, default, break
  • (C) for, while, switch
  • (D) case, break, if, else
Correct Answer: (B) switch, case, default, break
32. Which of the following data types can be used in a switch expression?
  • (A) Integer and character values only
  • (B) Float and double values
  • (C) String values
  • (D) Boolean values only
Correct Answer: (A) Integer and character values only
33. What is the purpose of the break statement in a switch block?
  • (A) To continue the next case
  • (B) To exit from the switch block
  • (C) To pause the switch block
  • (D) To stop the program execution
Correct Answer: (B) To exit from the switch block
34. If the switch expression does not match any case value, what will happen if a default statement is present?
  • (A) The default block will execute
  • (B) The program will exit
  • (C) The control will go to the first case
  • (D) The program will throw an error
Correct Answer: (A) The default block will execute
35. What must follow each case value in a switch statement?
  • (A) Semicolon ;
  • (B) Colon :
  • (C) Comma ,
  • (D) Braces {}
Correct Answer: (B) Colon :
36. In a switch statement, are case values required to be in a specific order?
  • (A) Yes
  • (B) No
Correct Answer: (B) No
37. What is a nested switch statement?
  • (A) A switch statement inside a loop
  • (B) A switch block within another switch block
  • (C) Multiple case values inside one switch
  • (D) A switch with no break statements
Correct Answer: (B) A switch block within another switch block
38. In the nested switch example, what happens if the inner switch statement does not have a matching case value?
  • (A) The program will stop
  • (B) The default block will execute if present
  • (C) The control will move out of the program
  • (D) The control will skip to the next iteration
Correct Answer: (B) The default block will execute if present
39. What is the output when no break is provided in a switch case?
  • (A) Only the matched case will execute
  • (B) All cases below the matched case will also execute
  • (C) The program will throw an error
  • (D) The program will skip all cases
Correct Answer: (B) All cases below the matched case will also execute
40. What will happen if the break keyword is not used after a case in a switch statement?
  • (A) Only the matched case will execute
  • (B) All subsequent cases will also execute until a break is encountered
  • (C) The program will stop
  • (D) The control will skip to the next iteration
Correct Answer: (B) All subsequent cases will also execute until a break is encountered