Back to questions
JuniorTheoryCommon
What does the program print?
fn main() {
println!("{} {}", 7 / 2, 7.0 / 2.0);
}3 3.5
- Expecting
3.5from7 / 2: dividing one integer by another gives an integer, and the fraction is dropped. - Expecting integer division to round:
7 / 2drops the.5and gives 3, never 4.
- How would you get 3.5 from two integer variables
a = 7andb = 2? - What does
-7 / 2give in Rust, and why?