Lesson 36 +10 XP

Operators Overview

C++ Operators

An operator is a little symbol that tells C++ to perform an operation on values. The values it works on are called operands.

The simplest example

int total = 100 + 5;
cout << total << endl;  // 105

The + symbol is the operator. It works on the operands 100 and 5, and the result is 105.

The four main groups

C++ operators are grouped by the job they do:

  • Arithmetic - +, -, *, /, % do math.
  • Assignment - =, +=, -= and more put values into variables.
  • Comparison - ==, !=, >, <, >=, <= ask questions.
  • Logical - &&, ||, ! combine true and false.

Operators are everywhere

Operators are the verbs of a program. Adding up scores, comparing prices, or making a decision - every one of those uses an operator somewhere.

TL;DR

  • An operator performs an operation on some operands.
  • The main groups: arithmetic, assignment, comparison, logical.
  • In 100 + 5, the operator is + and the operands are 100 and 5.
  • C++ code uses operators constantly.