0PricingLogin
Learn Rust Coding · Lesson

Scalar Types

Integers, floats, bool, char.

What Are Scalar Types?

A scalar type represents a single value. Rust has four primary scalar types:

  • Integers
  • Floating-point numbers
  • Booleans
  • Characters
fn main() {
    let i = 10;       // integer
    let f = 2.5;      // float
    let b = true;     // bool
    let c = 'R';      // char
    println!("{} {} {} {}", i, f, b, c);
}

Integer Types

Integers come in signed (i) and unsigned (u) variants with fixed sizes: i8, i16, i32, i64, i128, and the same for u.

The default integer type is i32.

fn main() {
    let small: i8 = -120;
    let big: u64 = 18_000_000_000;
    println!("{} {}", small, big);
}

All lessons in this course

  1. let and Mutability
  2. Scalar Types
  3. Compound Types
  4. Shadowing
← Back to Learn Rust Coding