0
0
Rustprogramming~5 mins

Output using println macro in Rust - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the println! macro do in Rust?
It prints text to the console followed by a new line, allowing you to display output to the user.
Click to reveal answer
beginner
How do you print a variable's value using println!?
Use curly braces {} as a placeholder inside the string, and pass the variable after the comma. Example: println!("Value: {}", x);
Click to reveal answer
beginner
What happens if you use println! without any arguments?
It prints an empty line (just a new line) to the console.
Click to reveal answer
intermediate
Can println! print multiple variables? How?
Yes, by using multiple placeholders {} and passing variables in order. Example: println!("{} and {}", a, b);
Click to reveal answer
intermediate
What is the difference between print! and println! macros?
print! prints text without adding a new line at the end, while println! adds a new line after printing.
Click to reveal answer
What will println!("Hello, {}!", "Rust"); output?
AHello, Rust!
BHello, {}!
CHello, "Rust"!
DError
Which macro adds a new line after printing?
Aprint!
Bprintln!
Cwrite!
Dformat!
How do you print two variables a and b using println!?
Aprintln!("{} {}", a, b);
Bprintln!(a, b);
Cprintln!("a and b");
Dprintln!("{}", a + b);
What does println!(); print?
ANothing
BA blank line
CError
DThe text 'println!'
Which of these is correct to print the value of variable x?
Aprintln!("x");
Bprintln!("{}", x);
Cprintln!(x);
Dprintln!("{x}");
Explain how to use the println! macro to print text and variables in Rust.
Think about how you combine text and values inside the macro.
You got /4 concepts.
    What is the difference between print! and println! macros? When would you use each?
    Consider how output appears on the console.
    You got /4 concepts.