Lesson 38 +10 XP

Operators Overview

Operators Overview

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;
printf("%d", total);  // 105

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

The four main groups

  • 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 uses an operator.

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.