C Workshop · Operators
Foundation C

Operators

An operator takes values (operands) and produces a new value. Arithmetic, comparison, and logic are the everyday set.

What it is

An operator is a symbol that takes values and produces a new value. Plus adds, star multiplies, == asks “same?”, and && asks “both true?” The operator itself never prints — you print the result.

Approach

  1. Pick the operator that matches the question (times, compare, and/or).
  2. Write the expression with the operands.
  3. Print the result with a matching format (%d for ints).

Where this is used in the real world

Diagram

1

Operands

6 and 7 sit in memory

An operator never prints by itself.
2

Operator *

multiply

C also has + - / % and many others — see the cards below.
3

Result 42

the expression value

Integer math: 7 / 2 would be 3, not 3.5.
4

printf

show 42

Format %d matches int.

Run algorithm

Each step highlights the matching C line. Program output appears only when a line that prints actually runs.

Ready
C code
1#include <stdio.h>
2int main(void) {
3    int a = 6, b = 7;
4    printf("%d\n", a * b);
5    return 0;
6}
What this line does
Press Run algorithm. The highlight will move through the C code.
Program output
(no output yet)

Check your understanding

Five questions. Pick one answer each, then Check answers. The correct choice turns green.

1. 6 * 7 evaluates to:

Multiplication.

2. Integer 7 / 2 in C is:

Truncates toward zero for positive ints.

3. What does % do on ints?

Modulo.

4. An operator by itself prints:

You must print.

5. == vs = :

A classic C bug is if (n = 0).