Getting started
Quiz
What you learned
Getting started quiz. 13 questions. You need 80% to pass.
Which program compiles? First:
fn main() {
let mut v = vec![1, 2, 3];
let r1 = &v;
println!("{r1:?}");
let r2 = &mut v;
r2.push(4);
}Second:
fn main() {
let mut v = vec![1, 2, 3];
let r1 = &v;
let r2 = &mut v;
println!("{r1:?}");
}What does this print?
fn main() {
let x: i32 = 7 / 2;
println!("{x}");
}Same function, two files. What does each call do?
<?php
function add(int $a, int $b): int
{
return $a + $b;
}
echo add('5', 3);<?php
declare(strict_types=1);
function add(int $a, int $b): int
{
return $a + $b;
}
echo add('5', 3);What versions can this requirement resolve to?
[dependencies]
serde = "1"Cargo.toml gained a crate and Cargo.lock was not updated. What does this command do?
cargo build --lockedThe user presses Ctrl-D at the prompt. What does Ok(0) mean here?
let bytes = io::stdin()
.read_line(&mut line)
.expect("stdin should be readable");
if bytes == 0 {
return None;
}You are in the hello-cargo crate. Where is the binary after this command?
cargo build --releaseWhich file makes every laptop and CI use the same compiler for this repo?
[toolchain]
channel = "1.94"
components = ["rustfmt", "clippy"]The cursor should stay on the prompt line, before the program reads. Which call needs an explicit flush, and why?
print!("First number: ");println!("First number: ");What does this print?
fn main() {
let n = 7i32.checked_div(0);
println!("{n:?}");
}You are fixing a type error and do not need to run the program. Which command does less work?
cargo check
cargo buildYou ran cargo add --dev pretty_assertions. Where can that crate be used?
[dev-dependencies]
pretty_assertions = "1"You need nightly for one crate that uses an unstable feature. Which command is the right habit?
Will this compile?
fn main() {
let mut n = 1;
let r = &n;
n += 1;
println!("{r}");
}What does this print?
fn main() {
let v = vec![1, 2, 3];
let n: usize = v.iter().map(|x| x * 2).filter(|x| *x > 2).count();
println!("{n}");
}