Back to questions
JuniorTheoryOccasional
What does the program print?
fn main() {
let a = 2;
let b = 3;
println!("{} + {} = {}", a, b, a + b);
}2 + 3 = 5
- Expecting
2 + 3 = 23:aandbare integers, soa + bis computed as 5 beforeprintln!puts it in place of the third{}. - Expecting only the numbers: the text between the placeholders belongs to the format string and prints exactly as written.
- How would you write the same line with the variable names inside the braces?
- Why is
{a + b}rejected inside the braces, and what do you write instead?