0Pricing
Zig Academy · Lesson

Arithmetic and Comparison Operators

The core math and relational operators.

Arithmetic and Comparison Operators is a free Zig Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Zig Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Math, the Zig Way

Zig gives you the everyday math operators you expect, but with one promise: nothing happens behind your back. Every operation is explicit and predictable.

The Four Basics

You add, subtract, multiply, and divide with +, -, *, and /. They read exactly like ordinary arithmetic, so simple math feels natural. 🙂

const sum = 2 + 3;
const product = 4 * 5;

Operands Must Match

Both sides of an arithmetic operator must share the same type. Zig will not silently mix an i32 with an f64 for you; you convert on purpose.

const a: i32 = 10;
const b: i32 = 3;
const c = a + b;

Integer Division Truncates

When you divide two integers, the result is also an integer and the fraction is dropped toward zero. So 7 / 2 gives you 3, not 3.5.

const half = 7 / 2; // 3

The Remainder Operator

Use % to get what is left over after division. It is perfect for checks like even-or-odd, where 10 % 2 equals 0.

const leftover = 10 % 3; // 1

Negation Flips the Sign

A single minus in front of a value negates it. Writing -x simply turns a positive number negative, and a negative one positive.

const x = 5;
const neg = -x; // -5

Comparing Two Values

Comparison operators ask a yes-or-no question and hand you back a bool. The answer is always either true or false, never a number.

const isBigger = 7 > 3; // true

Equal and Not Equal

Check sameness with == and difference with !=. These let you confirm whether two values match before you act on them.

const same = 4 == 4; // true
const diff = 4 != 5; // true

Ordering Values

The operators <, <=, >, and >= compare order. They tell you whether one value sits below, at, or above another.

const ok = 3 <= 3; // true

Comparisons Drive Decisions

Because each comparison yields a clean bool, it slots straight into an if. That is how your program chooses one path over another.

if (score > 90) {
    // top marks
}

No Hidden Conversions

Zig refuses to quietly reshape your numbers during math or comparison. This strictness keeps results exact and surprise-free as programs grow.

Quick Check

What does integer division do with the fractional part?

Recap: Operators You Own

You now wield +, -, *, /, and % for math and comparisons that return a clean bool. Everything is explicit, exact, and yours to control. 🎯

Frequently asked questions

Is the “Arithmetic and Comparison Operators” lesson free?

Yes — the full text of “Arithmetic and Comparison Operators” is free to read here on the web, and the Zig Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Zig Academy course, upgrade to CoddyKit PRO.

What will I learn in “Arithmetic and Comparison Operators”?

The core math and relational operators. You practise Zig Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Zig Academy?

No prior experience is required. Zig Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Arithmetic and Comparison Operators” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Zig Academy lesson?

Yes. Every Zig Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Arithmetic and Comparison Operators
  2. Overflow: + vs +% vs +|
  3. Bitwise Operators
  4. Boolean Logic and Short-Circuiting
← Back to Zig Academy