What does this print?
fn main() {
println!("{}", size_of::<i64>());
println!("{}", size_of::<bool>());
}Running it prints:
8 1
Practice 05
Read each program and pick an answer. Some programs do not compile, and that can be the right answer. Your choice is checked as soon as you pick it, and saved in this browser.Need a refresher? Read lesson 5.
0 of 50 answered·0 correct
What does this print?
fn main() {
println!("{}", size_of::<i64>());
println!("{}", size_of::<bool>());
}Running it prints:
8 1
What does this print?
fn main() {
println!("{}", size_of::<[bool; 50]>());
}Running it prints:
50
What does this print? The three fields of a String sit on the stack even when the text is on the heap.
fn main() {
println!("{}", size_of::<String>());
println!("{}", size_of::<&str>());
}Running it prints:
24 16
What does this print?
fn main() {
let n: i32 = 10;
let pair = (n, n);
println!("{}", size_of_val(&n));
println!("{}", size_of_val(&pair));
}Running it prints:
4 8
What does this print?
fn main() {
println!("{}", size_of::<i32>());
println!("{}", size_of::<i64>());
println!("{}", size_of::<bool>());
println!("{}", size_of::<(i32, i32)>());
}Running it prints:
4 8 1 8
What does this print?
fn main() {
println!("{}", size_of::<[u8; 10]>());
println!("{}", size_of::<[u32; 10]>());
}Running it prints:
10 40
What does this print? A char holds one character, in any language, so it always takes four bytes.
fn main() {
println!("{}", size_of::<char>());
println!("{}", size_of::<[char; 3]>());
}Running it prints:
4 12
What does this print?
fn main() {
println!("{}", size_of::<u8>());
println!("{}", size_of::<u16>());
println!("{}", size_of::<u32>());
println!("{}", size_of::<u64>());
}Running it prints:
1 2 4 8
What does this print? () is the tuple with nothing in it.
fn main() {
println!("{}", size_of::<i8>());
println!("{}", size_of::<i128>());
println!("{}", size_of::<()>());
}Running it prints:
1 16 0
What does this print?
fn main() {
println!("{}", size_of::<f32>());
println!("{}", size_of::<f64>());
}Running it prints:
4 8
usize is the type for a size or a position. What does this print?
fn main() {
let n: usize = 1000;
println!("{}", n);
println!("{}", size_of::<usize>());
}Running it prints:
1000 8
What does this print?
fn main() {
println!("{}", size_of::<(bool, bool)>());
println!("{}", size_of::<[bool; 5]>());
println!("{}", size_of::<(i32, i32, i32)>());
println!("{}", size_of::<(f64, f64)>());
println!("{}", size_of::<(char, char)>());
}Running it prints:
2 5 12 16 8
What does this print?
fn main() {
println!("{}", size_of::<[i64; 5]>());
println!("{}", size_of::<(u16, u16, u16, u16)>());
}Running it prints:
40 8
What does this print?
fn main() {
println!("{}", size_of::<[(i32, i32); 3]>());
}Running it prints:
24
What does this print?
fn main() {
println!("{}", size_of::<((i32, i32), (i32, i32))>());
}Running it prints:
16
What does this print? The two lines ask the same question in two different ways.
fn main() {
println!("{}", size_of::<[i32; 3]>() + size_of::<[i32; 3]>());
println!("{}", size_of::<[i32; 6]>());
}Running it prints:
24 24
What does this print? This is an array of three arrays, each holding two numbers.
fn main() {
println!("{}", size_of::<[[i32; 2]; 3]>());
}Running it prints:
24
What does this print?
fn main() {
println!("{}", size_of::<((u8, u8), (u8, u8))>());
}Running it prints:
4
What does this print?
fn main() {
let x_size = size_of::<i16>() + size_of::<i16>();
let y_size = size_of::<i32>();
println!("{}", x_size == y_size);
}Running it prints:
true
Does this compile?
fn make_array(n: usize) {
let arr = [0; n];
println!("{:?}", arr);
}
fn main() {
make_array(5);
}The compiler says:
error[E0435]: attempt to use a non-constant value in a constant
Does this compile?
fn total(marks: [i32; 3]) -> i32 {
marks[0] + marks[1] + marks[2]
}
fn main() {
let marks = [72, 45, 90, 61];
println!("{}", total(marks));
}The compiler says:
error[E0308]: mismatched types
What does this print?
fn main() {
let a = 5;
let b = a;
println!("{a} {b}");
}Running it prints:
5 5
What does this print?
fn main() {
let a = 5;
let mut b = a;
b += 10;
println!("{a} {b}");
}Running it prints:
5 15
What does this print?
fn main() {
let ready = true;
let copy = ready;
println!("{ready} {copy}");
}Running it prints:
true true
What does this print?
fn main() {
let letter = 'x';
let copy = letter;
println!("{letter}{copy}");
}Running it prints:
xx
What does this print?
fn main() {
let a = (3, 4);
let b = a;
println!("{} {}", a.0, b.1);
}Running it prints:
3 4
What does this print?
fn main() {
let point = (1, 2);
let mut moved = point;
moved.0 = 9;
println!("{:?} {:?}", point, moved);
}Running it prints:
(1, 2) (9, 2)
What does this print?
fn main() {
let a = [1, 2, 3];
let mut b = a;
b[0] = 99;
println!("{:?} {:?}", a, b);
}Running it prints:
[1, 2, 3] [99, 2, 3]
What does this print?
fn main() {
let a = 5;
let a = a + 1;
let b = a;
println!("{a} {b}");
}Running it prints:
6 6
What does this print?
fn change(mut n: i32) {
n += 100;
println!("inside: {n}");
}
fn main() {
let n = 5;
change(n);
println!("outside: {n}");
}Running it prints:
inside: 105 outside: 5
What does this print?
fn zero(mut arr: [i32; 3]) {
arr[0] = 0;
println!("inside: {:?}", arr);
}
fn main() {
let marks = [72, 45, 90];
zero(marks);
println!("outside: {:?}", marks);
}Running it prints:
inside: [0, 45, 90] outside: [72, 45, 90]
What does this print?
fn one() -> i32 {
println!("one runs");
1
}
fn two() -> i32 {
println!("two runs");
2
}
fn main() {
println!("{}", one() + two());
}Running it prints:
one runs two runs 3
What does this print?
fn double(n: i32) -> i32 {
n * 2
}
fn main() {
let a = 3;
let b = double(double(a));
println!("{a} {b}");
}Running it prints:
3 12
What does this print?
fn square(n: i32) -> i32 {
n * n
}
fn sum_of_squares(a: i32, b: i32) -> i32 {
square(a) + square(b)
}
fn main() {
println!("{}", sum_of_squares(3, 4));
}Running it prints:
25
What does this print?
fn a() {
println!("a starts");
b();
println!("a ends");
}
fn b() {
println!("b starts");
println!("b ends");
}
fn main() {
println!("main starts");
a();
println!("main ends");
}Running it prints:
main starts a starts b starts b ends a ends main ends
What does this print?
fn outer() {
println!("outer starts");
inner();
inner();
println!("outer ends");
}
fn inner() {
println!("inner");
}
fn main() {
outer();
}Running it prints:
outer starts inner inner outer ends
What does this print?
fn countdown(n: i32) {
println!("{n}");
if n > 0 {
countdown(n - 1);
}
}
fn main() {
countdown(3);
}Running it prints:
3 2 1 0
This calls itself the same way question 37 does, but the println! has moved. What does it print?
fn countdown(n: i32) {
if n > 0 {
countdown(n - 1);
}
println!("{n}");
}
fn main() {
countdown(3);
}Running it prints:
0 1 2 3
What does this print?
fn factorial(n: u32) -> u32 {
if n == 0 {
1
} else {
n * factorial(n - 1)
}
}
fn main() {
println!("{}", factorial(5));
}Running it prints:
120
What does this print?
fn sum_to(n: u32) -> u32 {
if n == 0 {
0
} else {
n + sum_to(n - 1)
}
}
fn main() {
println!("{}", sum_to(4));
}Running it prints:
10
What does this print?
fn fib(n: u32) -> u32 {
if n < 2 {
n
} else {
fib(n - 1) + fib(n - 2)
}
}
fn main() {
println!("{}", fib(6));
}Running it prints:
8
What does this print?
fn triple(n: i32) -> i32 {
n * 3
}
fn main() {
println!("{}", triple(triple(2)));
}Running it prints:
18
What does this print?
fn frame_bytes(n: u32) -> u32 {
let a = 0u8;
let b = 0u8;
let local = (size_of::<u8>() + size_of::<u8>()) as u32;
println!("{a}{b}");
if n == 0 {
local
} else {
local + frame_bytes(n - 1)
}
}
fn main() {
println!("{}", frame_bytes(2));
}Running it prints:
00 00 00 6
What does this print?
fn main() {
let total = size_of::<i32>() + size_of::<u8>() + size_of::<bool>();
println!("{total}");
}Running it prints:
6
What does this print?
fn main() {
let total = size_of::<[i32; 3]>() + size_of::<f64>();
println!("{total}");
}Running it prints:
20
What does this print?
fn main() {
let a_size = size_of::<u8>();
let b_size = size_of::<u8>();
let c_size = size_of::<[u8; 8]>();
println!("{}", a_size + b_size + c_size);
}Running it prints:
10
What does this print?
fn main() {
let total = size_of::<[u8; 4]>() + size_of::<u32>();
println!("{total}");
}Running it prints:
8
What does this print?
fn main() {
let a_size = size_of::<i32>();
let b_size = size_of::<i32>();
let c_size = size_of::<i32>();
println!("{}", a_size + b_size + c_size);
}Running it prints:
12
The stack starts at address 1000 for this one. What does this print?
fn main() {
const STACK_START: u32 = 1000;
let a_size = size_of::<u32>() as u32;
let b_size = size_of::<bool>() as u32;
println!("{}", STACK_START + a_size + b_size);
}Running it prints:
1005
Each call adds one u32 to the running total. What does this print?
fn frame(n: u32) -> u32 {
let local = size_of::<u32>() as u32;
if n == 0 {
local
} else {
local + frame(n - 1)
}
}
fn main() {
println!("{}", frame(3));
}Running it prints:
16