Recall & Review
beginner
What macro is commonly used in Rust to print formatted output to the console?
The
println! macro is used to print formatted output to the console in Rust.Click to reveal answer
beginner
How do you insert a variable's value inside a string using Rust's formatting syntax?
Use curly braces
{} as placeholders inside the string, and pass the variable after the comma. For example: println!("Value: {}", x);Click to reveal answer
intermediate
What does the format specifier
{:.2} do in Rust's formatting?It formats a floating-point number to show exactly 2 digits after the decimal point.
Click to reveal answer
intermediate
How can you align text to the right with a width of 10 characters in Rust formatting?
Use
{:>10} inside the format string. This pads the text on the left to make the total width 10 characters.Click to reveal answer
beginner
What is the difference between
print! and println! macros in Rust?print! outputs text without adding a new line at the end, while println! adds a new line after printing.Click to reveal answer
Which macro in Rust adds a newline after printing?
✗ Incorrect
println! prints text and adds a newline. print! does not add a newline.How do you format a floating-point number to 3 decimal places in Rust?
✗ Incorrect
The syntax
{:.3} formats a float to 3 decimal places.What does
{:>8} do in a format string?✗ Incorrect
{:>8} right-aligns the text and pads with spaces to width 8.Which macro returns a formatted string without printing it?
✗ Incorrect
format! creates a formatted string but does not print it.How do you include a literal curly brace character in a Rust format string?
✗ Incorrect
Double braces
{{ or }} print a literal curly brace.Explain how to format a floating-point number to 2 decimal places and align it right with width 10 in Rust.
Think about combining precision and alignment inside the curly braces.
You got /3 concepts.
Describe the difference between print!, println!, and format! macros in Rust.
Consider what each macro does with the output.
You got /3 concepts.