5rustdatatypes

Understanding Data Types in Rust

In this guide, we’ll explore the different data types in Rust, a powerful systems programming language. Knowing data types is essential for writing effective Rust programs.


Data Types in Rust

Rust has several built-in data types, which can be categorized into two main types: scalar and compound types.

  • Scalar Types: These represent a single value.
    • i32: A 32-bit signed integer. Example: let age: i32 = 30;
    • f64: A 64-bit floating point number. Example: let height: f64 = 5.9;
    • char: A single character. Example: let letter: char = 'A';
    • bool: A boolean value, either true or false. Example: let is_student: bool = true;
  • Compound Types: These can combine multiple values.
    • Tuple: A fixed-size collection of values of different types. Example: let person: (&str, i32) = ("Alice", 30);
    • Array: A collection of elements of the same type with a fixed length. Example: let numbers: [i32; 5] = [1, 2, 3, 4, 5];
0 Interaction
224 Views
Views
46 Likes
×
×
🍪 CookieConsent@Ptutorials:~

Welcome to Ptutorials

Note: We aim to make learning easier by sharing top-quality tutorials.

We kindly ask that you refrain from posting interactions unrelated to web development, such as political, sports, or other non-web-related content. Please be respectful and interact with other members in a friendly manner. By participating in discussions and providing valuable answers, you can earn points and level up your profile.

$ Allow cookies on this site ? (y/n)

top-home