Scalar data types represent a single value. They include integers, floating-point numbers, Booleans, and characters.
Click to reveal answer
beginner
Name the four main scalar data types in Rust.
The four main scalar types are: integers, floating-point numbers, Booleans, and characters.
Click to reveal answer
beginner
What is the difference between an integer and a floating-point number in Rust?
An integer is a whole number without decimals, like 5 or -3. A floating-point number has decimals, like 3.14 or -0.001.
Click to reveal answer
beginner
How many values can a Boolean hold in Rust, and what are they?
A Boolean can hold exactly two values: true or false.
Click to reveal answer
beginner
What kind of values does the char type hold in Rust?
The char type holds a single Unicode scalar value, like a letter, number, or symbol, for example, 'a', '7', or '❤'.
Click to reveal answer
Which of these is NOT a scalar data type in Rust?
AArray
BBoolean
CInteger
DCharacter
✗ Incorrect
Arrays are compound types, not scalar types. Scalar types hold a single value.
What value types can a Boolean hold in Rust?
A0 or 1
BAny number
Ctrue or false
DAny character
✗ Incorrect
Booleans only hold true or false values.
Which scalar type would you use to store the number 42?
Achar
Bfloating-point
CBoolean
Dinteger
✗ Incorrect
42 is a whole number, so it fits the integer type.
What does the char type represent in Rust?
AA string of text
BA single letter, number, or symbol
CA true or false value
DA decimal number
✗ Incorrect
char holds a single Unicode character.
Which scalar type would you use to store the value 3.14?
Afloating-point
BBoolean
Cinteger
Dchar
✗ Incorrect
3.14 has decimals, so it is a floating-point number.
Explain the four main scalar data types in Rust and give a simple example of each.
Think about whole numbers, decimals, true/false, and single characters.
You got /5 concepts.
Why are scalar data types important in programming? How do they differ from compound types?
Consider how data is stored and used in small pieces.
You got /4 concepts.
Practice
(1/5)
1. Which of the following is NOT a scalar data type in Rust?
easy
A. Integer
B. Boolean
C. Array
D. Character
Solution
Step 1: Recall scalar data types in Rust
Scalar types include integers, floats, booleans, and characters, which hold a single value.
Step 2: Identify the non-scalar type
An array holds multiple values and is a compound type, not scalar.
Final Answer:
Array -> Option C
Quick Check:
Scalar types exclude arrays [OK]
Hint: Scalar types hold one value; arrays hold many [OK]
Common Mistakes:
Confusing arrays with scalar types
Thinking floats are not scalar
Mixing compound and scalar types
2. Which of the following is the correct way to declare a boolean variable named is_active set to true in Rust?
easy
A. let is_active: bool = true;
B. let is_active = True;
C. let is_active = 1;
D. let is_active: boolean = true;
Solution
Step 1: Check Rust boolean syntax
Rust uses lowercase true and false for booleans, and the type is bool.
Step 2: Validate each option
let is_active: bool = true; correctly declares is_active as a bool with value true. let is_active = True; uses uppercase True which is invalid. let is_active = 1; assigns an integer, not a boolean. let is_active: boolean = true; uses boolean which is not a Rust type.
Final Answer:
let is_active: bool = true; -> Option A
Quick Check:
Boolean type is bool and value is lowercase true [OK]
Hint: Booleans use lowercase true/false and type bool [OK]
Common Mistakes:
Using uppercase True/False
Using wrong type name boolean
Assigning integers to booleans
3. What will be the output of the following Rust code?
let x: i32 = 10;
let y: f64 = 3.5;
println!("{}", x as f64 + y);
medium
A. 13
B. 13.5
C. Type error
D. 10.0
Solution
Step 1: Understand type casting in the code
The integer x is cast to f64 using as f64, so 10 becomes 10.0.
Step 2: Perform the addition
Adding 10.0 (casted x) and 3.5 (y) results in 13.5.
Final Answer:
13.5 -> Option B
Quick Check:
Cast integer to float, then add floats = 13.5 [OK]
Hint: Cast integers to float before adding floats [OK]
Common Mistakes:
Forgetting to cast integer
Expecting integer addition
Assuming type error without cast
4. Identify the error in the following Rust code snippet:
let letter: char = "a";
medium
A. Missing semicolon
B. char cannot be assigned a letter
C. Variable name is invalid
D. char type must use single quotes, not double quotes
Solution
Step 1: Check char literal syntax
In Rust, char literals must be enclosed in single quotes, e.g., 'a', not double quotes.
Step 2: Analyze the code
The code uses double quotes "a", which is a string slice, not a char. This causes a type mismatch error.
Final Answer:
char type must use single quotes, not double quotes -> Option D
Quick Check:
char literals use single quotes 'a' [OK]
Hint: Use single quotes for char, double quotes for strings [OK]
Common Mistakes:
Using double quotes for char
Confusing char with string
Ignoring type mismatch errors
5. You want to store the temperature reading 36.6 in Rust using scalar types. Which declaration is best and why?
Options:
A) let temp: i32 = 36.6;
B) let temp: char = '36';
C) let temp: bool = true;
D) let temp: f64 = 36.6;
hard
A. let temp: f64 = 36.6; because floats store decimal numbers
B. let temp: char = '36'; because characters store numbers
C. let temp: bool = true; because temperature is true or false
D. let temp: i32 = 36.6; because integers store decimal numbers
Solution
Step 1: Understand the data type needed for decimal numbers
Temperature 36.6 has a decimal part, so it requires a floating-point type like f64.
Step 2: Evaluate each option
let temp: i32 = 36.6; because integers store decimal numbers tries to assign a decimal to an integer, which is invalid. let temp: f64 = 36.6; because floats store decimal numbers correctly uses f64 for decimals. let temp: bool = true; because temperature is true or false uses boolean, which is unrelated. let temp: char = '36'; because characters store numbers uses char with invalid multi-character literal.
Final Answer:
let temp: f64 = 36.6; because floats store decimal numbers -> Option A
Quick Check:
Decimal numbers need float types like f64 [OK]
Hint: Use float types for decimal numbers like temperature [OK]
Common Mistakes:
Assigning decimals to integers
Using bool for numeric values
Using char for multi-digit numbers
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.