C++ - Logical Operators

Overview

Estimated time: 15–25 minutes

Combine predicates with logical and/or and negate with not.

Learning Objectives

  • Use &&, ||, and ! with boolean expressions.
  • Understand short-circuit evaluation.

Examples

bool ok = (x>0 && y>0);

Common Pitfalls

  • Assuming both sides are always evaluated; && and || short-circuit.