0
0
C++programming~10 mins

Logical operators in C++ - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if both conditions are true.

C++
bool result = (a > 5) [1] (b < 10);
Drag options to blanks, or click blank then click option'
A!
B&&
C||
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise AND (&) instead of logical AND (&&).
Using logical OR (||) when both conditions must be true.
2fill in blank
medium

Complete the code to check if either condition is true.

C++
bool result = (x == 0) [1] (y != 0);
Drag options to blanks, or click blank then click option'
A&&
B&
C!
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical AND (&&) when only one condition needs to be true.
Using bitwise OR (|) instead of logical OR (||).
3fill in blank
hard

Fix the error in the condition to correctly negate the expression.

C++
if ([1]) {
    // do something
}
Drag options to blanks, or click blank then click option'
A!flag
B~flag
C!!flag
Dflag
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise NOT (~) instead of logical NOT (!).
Not negating the flag when needed.
4fill in blank
hard

Fill both blanks to create a condition that is true only if a is positive and b is not zero.

C++
if ((a [1] 0) [2] (b != 0)) {
    // code here
}
Drag options to blanks, or click blank then click option'
A>
B&&
C||
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical OR (||) instead of AND (&&) when both conditions must be true.
Using less than (<) instead of greater than (>) for positive check.
5fill in blank
hard

Fill all three blanks to create a condition that is true if x is zero or y is positive and z is false.

C++
if ((x [1] 0) [2] (y [3] 0 && !z)) {
    // action
}
Drag options to blanks, or click blank then click option'
A==
B||
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical AND (&&) instead of OR (||) between x and y conditions.
Using less than (<) instead of greater than (>) for y check.