Complete the code to declare a 32-bit signed integer variable named num with the value 10.
let num: [1] = 10;
u32 which is unsigned and might not be intended here.f32 for integers.The i32 type is a 32-bit signed integer in Rust, suitable for storing the value 10.
Complete the code to declare an unsigned 8-bit integer variable named age with the value 25.
let age: [1] = 25;
i8 which allow negative numbers.bool which is not numeric.The u8 type is an 8-bit unsigned integer, perfect for small positive numbers like 25.
Fix the error in the code by choosing the correct integer type for the variable count initialized with 1000.
let count: [1] = 1000;
i8 or u8 which are too small for 1000.bool which is not numeric.The value 1000 is too large for i8 or u8 which only hold up to 127 and 255 respectively. i16 can hold values up to 32767.
Fill both blanks to create a dictionary that maps numbers to their squares for numbers 1 to 3, using the correct integer types and operators.
let squares = std::collections::HashMap::from([(1[1] 3, 1[2] 3)]);
.. which excludes the last number.The ..= operator creates an inclusive range from 1 to 3. The * operator calculates the square of each number.
Fill both blanks to create a HashMap that stores the length of each word only if the length is greater than 3.
let lengths = words.iter().filter(|&word| word.len() [1] 3).map(|word| (word.to_string(), word.len() [2] ,)).collect::<std::collections::HashMap<_, _>>();
The filter uses > to select words longer than 3. The map creates tuples with the word and its length minus 1, separated by a comma.