CMSC330_12/01

CMSC 330 — Fall 2026 · December 01, 2026 · 171 players · Max 10 pts

Questions & Results

Q1 of 10Multiple ChoiceAccuracy60s · 1 pt

What is the output?

let s = String::from("Rust is fun!");
let h = &s[5..7];
println!("{}", h);
A `Rust`
B `is`
130
✓ Correct
C `fun!`
1
D Type error
131 / 171 answered · 99% correct
Q2 of 10Multiple ChoiceAccuracy60s · 1 pt

What is the output?

let mut s1 = String::from("Go");
let s2 = " Terps";
s1.push_str(s2);
println!("[{}] [{}]", s1, s2);
A `[Go Terps] [ Terps]`
154
✓ Correct
B `[Go Terps] [Go Terps]`
3
C `[Go] [ Terps]`
4
D Compile error: `s2` gave up ownership to `s1`
1
162 / 171 answered · 95% correct
Q3 of 10Multiple ChoiceAccuracy60s · 1 pt

What is the output?

let s1 = String::from("CMSC");
let s3;
{
  let s2 = String::from("330");
  s3 = s1 + &s2;
  println!("{}", s2);
}
println!("{}", s3);
A `330`, then `CMSC330`
116
✓ Correct
B `330`, then `CMSC`
3
C Compile error: `s2` was moved into `s3`
21
D Compile error: `s2` does not live long enough
26
166 / 171 answered · 70% correct
Q4 of 10Multiple ChoiceAccuracy60s · 1 pt

What is the output?

use std::collections::HashMap;

fn main() {
  let mut h = HashMap::new();
  h.insert("Ana", "1");
  h.insert("Ben", "2");
  h.insert("Ana", "3");
  match h.get(&"Ana") {
    Some(&id) => println!("Ana:{}", id),
    _ => println!("Not Found"),
  }
}
A `Ana:1`
3
B `Ana:3`
165
✓ Correct
C `Not Found`
1
D Compile error
169 / 171 answered · 98% correct
Q5 of 10Multiple ChoiceAccuracy60s · 1 pt

What is the output?

let v = vec![1, 2, 3, 4, 5];
println!("{:?}", v.get(100));
let oops = &v[100];
println!("{}", oops);
A Prints `None`, then panics: index out of bounds
127
✓ Correct
B Prints `None` twice
8
C Compile error: index out of bounds
17
D Panics at `v.get(100)`
18
170 / 171 answered · 75% correct
Q6 of 10Multiple ChoiceAccuracy60s · 1 pt

What is the output?

struct Rectangle {
  width: u32,
  height: u32,
}

fn main() {
  let r = Rectangle { width: 30, height: 50 };
  println!("{}", r);
}
A `Rectangle { width: 30, height: 50 }`
1
B `30 50`
C Compile error: `Rectangle` doesn't implement `Display`
169
✓ Correct
D Compile error: `r` must be declared `mut`
170 / 171 answered · 99% correct
Q7 of 10Multiple ChoiceAccuracy60s · 1 pt

True or false: point.y = 6; would compile at // HERE.

struct Point {
  x: i32,
  y: i32,
}

fn main() {
  let point = Point { x: 0, y: 0 };
  let mut point = point;
  // HERE
}
A True
143
✓ Correct
B False
26
169 / 171 answered · 85% correct
Q8 of 10Multiple ChoiceAccuracy60s · 1 pt

What is the output?

#[derive(Debug)]
struct Point {
  x: i32,
  y: i32,
}

impl Point {
  fn m(&mut self) {
    self.x += 1;
    self.y += 2;
  }
}

fn main() {
  let mut p = Point { x: 0, y: 0 };
  p.m();
  p.m();
  println!("{:?}", p);
}
A `Point { x: 2, y: 4 }`
165
✓ Correct
B `Point { x: 1, y: 2 }`
1
C `Point { 2,4 }`
2
D `Point { x: 0, y: 0 }`
1
169 / 171 answered · 98% correct
Q9 of 10Multiple ChoiceAccuracy60s · 1 pt

What is the output?

#[derive(Debug)]
enum Auth {
  Enabled(i32),
  Disabled(i32),
}

fn main() {
  let yes = Auth::Enabled(1);
  let no = Auth::Disabled(0);
  println!("{:?}", no);
}
A `Enabled(1)`
B `Disabled(0)`
169
✓ Correct
C `Auth::Disabled(0)`
D `0`
169 / 171 answered · 100% correct
Q10 of 10Multiple ChoiceAccuracy60s · 1 pt

What is the output?

enum Number {
  Zero,
  One,
  Two,
}

fn main() {
  use Number::Zero;
  let t = Number::Two;
  match t {
    Zero => println!("0"),
    Number::One => println!("1"),
    _ => println!("other"),
  }
}
A `0`
B `1`
2
C `other`
163
✓ Correct
D Compile error
165 / 171 answered · 99% correct

Score Distribution

1
1
3
5
8
33
70
50
0
1
2
3
4
5
6
7
8
9
10

Score (points) →

Players
171
Average Score
8.8
High Score
10
Max Possible
10