A

Admin • 833.24K Points
Coach

Q. What is the output of this code?

Code:
fn main() {
let x = vec![1, 2, 3];
println!("{}", x[1]);
}
  • (A) 1
  • (B) 2
  • (C) 3
  • (D) Compilation error
  • Correct Answer - Option(B)
  • Views: 23
  • Filed under category Rust
  • Hashtags:

Explanation by: Admin

Indexing starts at 0, so x[1] is 2.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.