Puzzle 4Byte-Sized Chunks
 fn​ ​main​() {
 let​ ​mut​ counter : i8 = 0;
 loop​ {
  println!(​"{}"​, counter);
  counter += 1;
  }
 }

Guess the Output

images/aside-icons/important.png

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

images/hline.png

The answer depends on how you run the program.

  • If you run the program in debug mode with cargo run, the program will display a series of numbers from 0 to 127 and then crash with the following error message: thread ’main’ panicked at ’attempt to add with overflow’, overflow\src\main.rs:6:9.

  • If you run the ...

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.