WorksheetsTEB2132 Lecture 3 Quiz
Total questions: 10
Worksheet time: 5mins
Which one is NOT a control structure in C++?
Sequence
Repetition
Execution
Selection
What is the type of operator != in C++?
relational
equality
logical
expression
A logical expression && returns 1 (true) if
Both operands are 1 (true)
Both operands are 0 (false)
One operand is 1 (true)
One operand is 0 (false)
Which operator is commonly used in an if condition to check equality in C++?
=
!=
===
==
Which keyword is used to exit a switch case immediately after executing a statement?
exit
break
stop
return
What will happen if the break statement is omitted in a switch case?
Program ends immediately
Only the current case runs
Execution continues into the next case
Compilation error
Which of the following data types can be used in a switch statement in C++?
bool
char
float
double
Which statement is true about if–else and switch?
if–else is used for range-based conditions, while switch works with discrete values.
switch can handle conditions with < or >.
Both can only be used with integers.
Both are identical in functionality.
What is the default block in a switch statement used for?
To terminate the program
To execute all cases together
To execute if no case matches
To initialize variables
Find the output:
char ch = 'b';
switch (ch) {
case 'a': cout << "Apple"; break;
case 'b': cout << "Ball"; break;
case 'c': cout << "Cat"; break;
default: cout << "None";
}
Apple
Ball
Cat
None
