Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The logical AND operator in C is &&. It returns true only if both operands are true.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The logical OR operator in C is ||. It returns true if at least one operand is true.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'not' which is not valid C syntax.
Using ~ which is bitwise NOT, not logical NOT.
✗ Incorrect
The logical NOT operator in C is !. It negates the boolean value of flag.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using || instead of && which would check if either condition is true.
Using ~ instead of ! which is bitwise NOT.
✗ Incorrect
Use && to check both conditions and ! to negate b.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using | or & which are bitwise operators, not logical.
Using || which would allow any condition to be true.
✗ Incorrect
Use && to combine conditions, ! to negate y, and && again to combine with z.