Puzzle 11Stacking Boxes
 fn​ ​main​() {
 let​ c = ​Box​::​new​([0u32; 10_000_000]);
  println!(​"{}"​, c​.len​());
 }

Guess the Output

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

images/hline.png

In debug mode, the program will crash with the message thread ’main’ has overflowed its stack. In release mode, the program will display the following output: 10000000.

images/hline.png

Discussion

10,000,000 32-bit integers requires 40Mb of memory ...

Get Rust Brain Teasers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.