LearnFrenzy
Sign in Take a free test

Decision Making · Exercise 1 of 4

Decision Making Decision Making MCQ

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

Twelve multiple-choice questions on truth values, De Morgan's laws, range checks, guard order, comparing strings and doubles, and choosing between if, switch and tables. Pick an option to check your answer instantly.

Question 1 Easy

What are the values of !0 and !5?

A 0 and -5
B 1 and 0
C 1 and 4
D true and false (bool)
Question page & discussion
Question 2 Easy

Which expression is equivalent to !(a && b)?

A !a && !b
B !a || !b
C a || b
D !(a || b)
Question page & discussion
Question 3 Easy

Which condition is true exactly when x is between 10 and 20, inclusive?

A 10 <= x <= 20
B x >= 10 || x <= 20
C x >= 10 && x <= 20
D x > 10 && x < 20
Question page & discussion
Question 4 Medium

p may be a null pointer. Which condition is safe?

A p->count > 0 && p != NULL
B p != NULL && p->count > 0
C p != NULL & p->count > 0
D Both orders are equally safe
Question page & discussion
Question 5 Easy

Which condition checks whether the string role equals "admin"?

A role == "admin"
B strcmp(role, "admin") == 0
C strcmp(role, "admin")
D *role == "admin"
Question page & discussion
Question 6 Medium

Two computed doubles should be treated as equal. Which condition is appropriate?

A a == b
B fabs(a - b) < 1e-9 (or a relative tolerance)
C (int) a == (int) b
D a - b == 0
Question page & discussion
Question 7 Easy

Without any else, which is equivalent to if (a) { if (b) { work(); } }?

A if (a || b) work();
B if (a && b) work();
C if (a) work(); if (b) work();
D if (!a && !b) work();
Question page & discussion
Question 8 Easy

For a pointer p, what does if (p) test?

A Whether *p is non-zero
B Whether p is not a null pointer
C Whether p points to a string
D It is a compile error
Question page & discussion
Question 9 Medium

What does bool ok = 42; store?

A 42
B 1 (true)
C 0
D It does not compile
Question page & discussion
Question 10 Hard

How do you test that exactly one of two int flags a and b (which may hold any value) is true?

A a ^ b
B !a != !b
C a != b
D a || b
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links