LearnFrenzy
Sign in Take a free test

Control Instructions · Exercise 1 of 4

Control Instructions Control Instructions MCQ

  • 12 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twelve multiple-choice questions on if-else, switch, fall-through, short-circuit evaluation, the conditional operator, goto and the C23 changes. Pick an option to check your answer instantly.

Question 1 Easy

In if (x), when is the condition true?

A Only when x is 1
B When x is any non-zero value
C When x is positive
D Only when x is of type bool
Question page & discussion
Question 2 Easy

What does if (x = 5) { … } do?

A Compares x with 5
B Assigns 5 to x, and the body always runs because 5 is non-zero
C It does not compile
D Assigns 5 only if x was 0
Question page & discussion
Question 3 Medium

In if (a) if (b) s1; else s2; (no braces), which if does the else belong to?

A if (a)
B if (b) – the nearest unmatched if
C Both
D It is a syntax error
Question page & discussion
Question 4 Easy

Which of these cannot be the controlling expression of a switch?

A char
B enum value
C long
D double
Question page & discussion
Question 5 Medium

Which statement about case labels is true?

A They can be any variable
B They must be distinct integer constant expressions
C They must be in ascending order
D They can be strings
Question page & discussion
Question 6 Easy

A matching case has no break. What happens after its statements run?

A The switch ends
B Execution continues into the next case's statements (fall-through)
C The default case runs
D A compile error
Question page & discussion
Question 7 Medium

Which is true about default in a switch?

A It must be last
B It can be anywhere and runs only when no case matches
C It runs every time
D Every switch must have one
Question page & discussion
Question 8 Easy

In if (n != 0 && total / n > 5), what happens when n is 0?

A Division by zero
B total / n is not evaluated, so there is no division by zero
C The program crashes
D Both sides are always evaluated
Question page & discussion
Question 9 Hard

What is the type of the expression flag ? 1 : 2.0?

A int
B double
C It depends on flag
D float
Question page & discussion
Question 10 Hard

Which use of goto is invalid?

A Jumping forward to a cleanup label
B Jumping out of two nested loops
C Jumping into the scope of a variable length array, past its declaration
D Jumping backwards to retry an operation
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links