rustHow to declare a matrix in Rust?
A matrix can be declared in Rust using a two-dimensional array. The following example code block shows how to declare a 3x3 matrix:
let matrix: [[i32; 3]; 3] = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
The output of the above code is:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
The code consists of the following parts:
let: This is a keyword used to declare a variable.matrix: This is the name of the variable.[[i32; 3]; 3]: This is the type of the variable. It is a two-dimensional array of typei32with 3 elements in each row.[...]: This is the value of the variable. It is an array of 3 arrays, each containing 3 elements.
Helpful links
Related
More of Rust
- How do I identify unused variables in Rust?
- How to replace a capture group using Rust regex?
- How to match the end of a line in a Rust regex?
- How to use non-capturing groups in Rust regex?
- How to use regex captures in Rust?
- How to use negation in Rust regex?
- Regex example to match multiline string in Rust?
- How to use regex lookbehind in Rust?
- How to use regex to match a double quote in Rust?
- Generator example in Rust
See more codes...