<aside> 💡 Notion Tip: Tag pages to let collaborators know what they can expect to use the page for. You can add one or many tags to any page in a wiki.
</aside>
number/integer i
u=lebih strict ===
number/integer u u= untuk tidak menentukan string/integer misal "32" ==32
Table 3-1: Integer Types in Rust
Length | Signed | Unsigned |
---|---|---|
8-bit | i8 |
u8 |
16-bit | i16 |
u16 |
32-bit | i32 |
u32 |
64-bit | i64 |
u64 |
128-bit | i128 |
u128 |
arch | isize |
usize |
let guess: u32 = "42".parse().expect("Not a number!");
let sum = 5 + 10;
//PECAHAN f
// subtraction
let difference = 95.5 - 4.3;
// multiplication
let product = 4 * 30;
// division
let quotient = 56.7 / 32.2;
let truncated = -5 / 3; // Results in -1
// remainder
let remainder = 43 % 5;
//BOOLEAN
let t = true;
let f: bool = false; // with explicit type annotation
COMPOUNTD TYPE : rust mempunyai 2 compount type yaitu tup dan array
TUPLE TYPE : memasukan beberapa tipe data kedalam 1 type
let tup = (500, 6.4, 1);
let (x, y, z) = tup;
Array : tidak seperti tuple , setiap elemen memiiki tipe data yang sama. array harus ukuran/length yang fixed.
let months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
let a = [3; 5];
let a = [1, 2, 3, 4, 5];
let element = a[index];
println!("The value of the element at index {index} is: {element}");