RRust By Example
beginnerBasics

Primitive Types

Scalar and compound types in Rust: integers, floats, booleans, tuples, arrays.

Primitive Types

Scalar and compound types in Rust: integers, floats, booleans, tuples, arrays.

Difficulty

Beginner

Code

rust
fn main() {
    let x: i32 = 42;
    let y: f64 = 3.14;
    let active: bool = true;
    let letter: char = 'R';

    let tup: (i32, f64, char) = (1, 2.5, 'a');
    let (a, b, c) = tup;
    println!("{} {} {}", a, b, c);

    let arr: [i32; 3] = [10, 20, 30];
    println!("first: {}", arr[0]);
}

Explanation

Rust has scalar types (integers, floats, booleans, chars) and compound types (tuples, arrays).

Key Concepts

  • Read the code carefully and understand the data flow
  • Try modifying the example to see how it changes behavior
  • Run this code in the Rust Playground

Related Topics

Browse more examples in the basics category to build a complete understanding of this topic.

More Basics Examples