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 typei32
with 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 to use non-capturing groups in Rust regex?
- How to use Unicode in a regex in Rust?
- How to replace a capture group using Rust regex?
- How to match whitespace with a regex in Rust?
- How to replace all matches using Rust regex?
- How to split a string with Rust regex?
- How to generate struct from json in Rust
- How to replace strings using Rust regex?
- Example of yield_now in Rust?
- How to get pointer to variable in Rust
See more codes...