How to declare and print array in Rust

3 Answers

0 votes
fn main() {
    let arr = [3, 8, 9, 0, 12, 7];
    
    println!("{:?}", arr);
}






/*
run:

[3, 8, 9, 0, 12, 7]

*/

 



answered Oct 25, 2022 by avibootz
0 votes
fn main() {
    let arr:[i32; 6] = [3, 8, 9, 0, 12, 7];
    
    println!("{:?}", arr);
}






/*
run:

[3, 8, 9, 0, 12, 7]

*/

 



answered Oct 25, 2022 by avibootz
0 votes
fn main() {
    let arr:[i32; 6] = [3, 8, 9, 0, 12, 7];
    
    for index in 0..6 {
        println!("index: {} & value: {}",index, arr[index]);
    }
}






/*
run:

index: 0 & value: 3
index: 1 & value: 8
index: 2 & value: 9
index: 3 & value: 0
index: 4 & value: 12
index: 5 & value: 7

*/

 



answered Oct 25, 2022 by avibootz

Related questions

1 answer 124 views
2 answers 148 views
4 answers 206 views
206 views asked Oct 25, 2022 by avibootz
1 answer 107 views
1 answer 139 views
1 answer 165 views
...