Go Basics

Arithmetic Operators

Description

Standard math operators: `+` (add), `-` (subtract), `*` (multiply), `/` (divide), `%` (modulus). `++` and `--` for increment/decrement are statements, not expressions.

Pros & Cons

✅ Pros

  • Simplicity.

❌ Cons

  • Increment is a statement: You cannot do `x = i++`.

When to Use

Mathematical calculations.

Example

Math operations.

a := 10
b := 3
fmt.Println(a + b) // 13
fmt.Println(a % b) // 1 (Remainder)

a++ // Valid
// b = a++ // Invalid in Go

Best Practices

Be careful with integer division; `5/2` equals `2`.

← Go OperatorsAssignment Operators →