The '+' operator adds two numbers together. For example, 2 + 3 equals 5.
Click to reveal answer
beginner
How do you perform multiplication in Rust?
Use the '*' operator to multiply two numbers. For example, 4 * 5 equals 20.
Click to reveal answer
intermediate
What is the result of 10 / 3 in Rust when using integer types?
When dividing integers, Rust performs integer division, so 10 / 3 equals 3 (the decimal part is dropped).
Click to reveal answer
beginner
What does the '%' operator do in Rust?
The '%' operator gives the remainder of a division. For example, 10 % 3 equals 1.
Click to reveal answer
intermediate
Can you use arithmetic operators with floating-point numbers in Rust?
Yes, you can use '+', '-', '*', and '/' with floating-point numbers (like f32 or f64). The operations work as expected with decimals. The '%' operator is not supported for floating-point types in Rust.
Click to reveal answer
What is the result of 7 + 5 in Rust?
A75
B2
C12
DError
✗ Incorrect
The '+' operator adds numbers, so 7 + 5 equals 12.
Which operator gives the remainder of a division?
A%
B-
C+
D/
✗ Incorrect
The '%' operator returns the remainder after division.
What happens when you divide two integers in Rust and the result is not whole?
AIt rounds up
BIt rounds down
CIt returns a float
DIt drops the decimal part
✗ Incorrect
Integer division drops the decimal part, so 10 / 3 equals 3.
Which operator is used for multiplication in Rust?
A/
B*
C+
D-
✗ Incorrect
The '*' operator multiplies two numbers.
Can you use the '+' operator with floating-point numbers in Rust?
AYes
BNo
COnly with integers
DOnly with strings
✗ Incorrect
The '+' operator works with floating-point numbers as well as integers.
Explain how the '%' operator works in Rust and give an example.
Think about what is left after dividing one number by another.
You got /3 concepts.
Describe what happens when you divide two integers in Rust and the result is not a whole number.
Rust does not round but cuts off the decimal.
You got /3 concepts.
Practice
(1/5)
1. Which arithmetic operator in Rust is used to find the remainder of a division?
easy
A. The - operator
B. The / operator
C. The * operator
D. The % operator
Solution
Step 1: Understand the meaning of each operator
The / operator divides, * multiplies, - subtracts, and % gives the remainder after division.
Step 2: Identify the operator for remainder
The % operator returns the remainder when one number is divided by another.
Final Answer:
The % operator -> Option D
Quick Check:
Remainder operator = % [OK]
Hint: Remainder always uses % in math [OK]
Common Mistakes:
Confusing / with %, thinking / gives remainder
Using * or - for remainder
Mixing up operator symbols
2. Which of the following is the correct way to write multiplication of two variables a and b in Rust?
easy
A. a * b
B. a x b
C. a . b
D. a & b
Solution
Step 1: Recall Rust arithmetic syntax
Rust uses * for multiplication, not x, ., or &.
Step 2: Confirm correct operator
The expression a * b correctly multiplies a and b.
Final Answer:
a * b -> Option A
Quick Check:
Multiplication operator = * [OK]
Hint: Use * for multiplication in Rust [OK]
Common Mistakes:
Using x instead of *
Using . or & which are not arithmetic
Confusing syntax with other languages
3. What is the output of the following Rust code?
let x = 10;
let y = 3;
let result = x / y;
println!("{}", result);
medium
A. 4
B. 3.3333
C. 3
D. Syntax error
Solution
Step 1: Understand integer division in Rust
Both x and y are integers, so x / y performs integer division, dropping decimals.
Step 2: Calculate integer division
10 divided by 3 is 3.3333, but integer division truncates to 3.
Final Answer:
3 -> Option C
Quick Check:
Integer division truncates decimals = 3 [OK]
Hint: Integer division drops decimals, use floats for precise result [OK]
Common Mistakes:
Expecting decimal result with integer division
Confusing integer and float division
Assuming syntax error due to println!
4. Identify the error in this Rust code snippet:
let a = 5;
let b = 2;
let c = a / b.0;
println!("{}", c);
medium
A. Variables a and b are not declared
B. Using .0 on integer causes error
C. Missing semicolon after println!
D. Division operator / is invalid
Solution
Step 1: Analyze the expression a / b.0
The code tries to access .0 on b, which is an integer, not a tuple or struct.
Step 2: Understand why .0 causes error
Only tuples or structs have fields like .0; integers do not, so this causes a compile error.
Final Answer:
Using .0 on integer causes error -> Option B
Quick Check:
Integer has no .0 field = error [OK]
Hint: Only tuples/structs have .0, not integers [OK]
Common Mistakes:
Thinking / is invalid operator
Missing semicolon causes error
Assuming variables are undeclared
5. You want to calculate the average of two integers a and b in Rust and get a float result. Which code snippet correctly does this?
hard
A. let avg = (a + b) as f64 / 2.0;
B. let avg = (a + b) / 2.0;
C. let avg = (a + b) / 2;
D. let avg = (a + b) / 2 as f64;
Solution
Step 1: Understand type conversion for float division
To get a float result, convert integers to float before division.
Step 2: Check each option for correct syntax and types
let avg = (a + b) / 2; does integer division, no float result. let avg = (a + b) as f64 / 2.0; converts sum to f64, divides by 2.0 (float), correct. let avg = (a + b) / 2.0; divides integer sum by float 2.0 without conversion, invalid. let avg = (a + b) / 2 as f64; tries to cast 2 to f64 before division (due to `as` precedence), invalid.
Final Answer:
let avg = (a + b) as f64 / 2.0; -> Option A
Quick Check:
Convert to float before dividing by float [OK]
Hint: Cast sum to float before dividing by float [OK]
Common Mistakes:
Dividing integers by float without cast
Casting after division
Using integer division expecting float result
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.