What is the primary purpose of a conditional statement in programming?
A.
To perform complex mathematical calculations.
B.
To store large amounts of data in a variable.
C.
To make decisions and run different code blocks based on certain conditions.
D.
To repeat the same line of code exactly 10 times.
Which keyword is most commonly used to start a basic conditional statement?
A.
while
B.
if
C.
return
D.
function
In a conditional statement, a "boolean expression" must evaluate to one of which two values?
A.
Positive or Negative.
B.
Integer or String.
C.
True or False.
D.
Start or Stop.
Which part of an if-else structure executes if the initial condition is false?
A.
The if block.
B.
The else block.
C.
The switch block.
D.
The entire program stops.
What is "nesting" in the context of conditional statements?
A.
Placing one if statement inside another if statement.
B.
Combining two variables into a single string.
C.
Deleting old code that is no longer needed.
D.
Using a loop to skip a condition.
Which operator is used specifically to check if two values are exactly equal?
A.
=
B.
!=
C.
==
D.
>=
What happens if you forget a break statement at the end of a case in a switch block?
A.
The computer will crash immediately.
B.
The program will skip the next case.
C.
The code will "fall through" and execute the following case(s) even if they don't match.
D.
The default case will always run first.
If there are 5 conditions to be checked including the last option, how many else if statements need to be written?
A.
3
B.
4
C.
5
D.
6
Which component of the switch is similar to else in an if else statement?
A.
expression
B.
case
C.
value
D.
default
Which of the following is TRUE regarding the default case?
A.
It is mandatory in every switch block
B.
It must always be placed at the very end of the switch statement
C.
It is optional and executes if no case matches the expression
D.
It can only be used if there is at least one break in the code
Which of these is NOT a valid case label in C?
A.
case 'A':
B.
case 1 + 2:
C.
case x: (where x is an integer variable)
D.
case 10:
What is the output of the following code?
int x = 1;
switch (x) {
case 1: printf("One ");
case 2: printf("Two ");
default: printf("Done");
} A.
One
B.
One Two Done
C.
One Two
D.
Done
What will the following code result in?
int a = 97;
switch (a) {
case 'a': printf("Alpha "); break;
case 97: printf("97 "); break;
} A.
Alpha
B.
97
C.
Alpha 97
D.
Compile-time error due to duplicate case values