Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,955 questions

51,897 answers

573 users

How to create a jagged array using vectors in Rust

1 Answer

0 votes
fn main() {
    // Create a jagged array using vectors
    let jagged_array: Vec<Vec<i32>> = vec![
        vec![1, 2, 3],
        vec![4, 5],
        vec![6, 7, 8, 9],
    ];

    // Access elements in the jagged array
    for (i, row) in jagged_array.iter().enumerate() {
        println!("Row {}: {:?}", i, row);
        for (j, &val) in row.iter().enumerate() {
            println!("Element at [{}][{}] = {}", i, j, val);
        }
    }
}



/*
run:

Row 0: [1, 2, 3]
Element at [0][0] = 1
Element at [0][1] = 2
Element at [0][2] = 3
Row 1: [4, 5]
Element at [1][0] = 4
Element at [1][1] = 5
Row 2: [6, 7, 8, 9]
Element at [2][0] = 6
Element at [2][1] = 7
Element at [2][2] = 8
Element at [2][3] = 9
     
*/
 

 



answered Mar 5, 2025 by avibootz

Related questions

1 answer 54 views
1 answer 88 views
1 answer 100 views
1 answer 111 views
1 answer 88 views
88 views asked Oct 9, 2024 by avibootz
...