0
0
Cprogramming~10 mins

Logical operators - 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 a and b are true using the logical AND operator.

C
if (a [1] b) {
    printf("Both are true\n");
}
Drag options to blanks, or click blank then click option'
A||
B|
C&&
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using | instead of && which is a bitwise OR, not logical AND.
Using || which checks if either condition is true, not both.
2fill in blank
medium

Complete the code to check if either x or y is true using the logical OR operator.

C
if (x [1] y) {
    printf("At least one is true\n");
}
Drag options to blanks, or click blank then click option'
A||
B|
C&
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using & instead of || which is a bitwise AND, not logical OR.
Using && which requires both conditions to be true.
3fill in blank
hard

Fix the error in the condition to check if not flag is true.

C
if ([1]flag) {
    printf("Flag is false\n");
}
Drag options to blanks, or click blank then click option'
A!
Bnot
Cflag
D~
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'not' which is not valid C syntax.
Using ~ which is bitwise NOT, not logical NOT.
4fill in blank
hard

Fill both blanks to check if a is true and b is false.

C
if (a [1] [2]b) {
    printf("a is true and b is false\n");
}
Drag options to blanks, or click blank then click option'
A&&
B||
C!
D~
Attempts:
3 left
💡 Hint
Common Mistakes
Using || instead of && which would check if either condition is true.
Using ~ instead of ! which is bitwise NOT.
5fill in blank
hard

Fill all three blanks to check if x is true, y is false, and z is true.

C
if (x [1] [2]y [3] z) {
    printf("x true, y false, z true\n");
}
Drag options to blanks, or click blank then click option'
A&&
B||
C!
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using | or & which are bitwise operators, not logical.
Using || which would allow any condition to be true.