Basics
Arithmetic
Integers and Division
Integer arithmetic in Rust truncates division and exposes the remainder with %.
Program
Play the program to compute an integer quotient and remainder.
arithmetic.rs
fn main() {
let a = 7;
let b = 2;
let quotient = a / b;
let remainder = a % b;
println!("{quotient} {remainder}");
}
integer division
`7 / 2` truncates toward zero, giving `3`.
modulo
`7 % 2` is the remainder `1`.
immutable bindings
`a` and `b` are read-only after binding.