CompTIA Tech+ (FC0-U71)Software Development ConceptsEasy

A technician is debugging a script that should display a greeting only if the user is logged in AND has administrator privileges. Which logical operator should be used to combine these two conditions?

  1. ANOT
  2. BOR
  3. CXOR
  4. DAND
Show answer & explanation

Correct answer: D. AND

The AND logical operator is used when both conditions must be true for the combined expression to be true. In this scenario, the user must be logged in AND have administrator privileges, so both conditions need to be satisfied.

Why the other options are wrong

  • A. NOT negates a single condition, which is not suitable for combining two conditions.
  • B. OR would display the greeting if either condition is true, which is not the requirement.
  • C. XOR (exclusive OR) would display the greeting if exactly one condition is true, but not both.

Logical AND Operator

A Boolean operator that returns true only if all of its operands are true. If any operand is false, the result is false.

  • Requires all conditions to be true.
  • Used to combine multiple conditions.
  • Commonly represented as '&&' or 'AND'.

Memory trick: AND means 'both' must be true.

More Software Development Concepts questions