LinkedIn skill assessment answers and questions — Rust (Lugha ya Kupanga)
“Kutu is a modern and innovative programming language that has gained popularity for its focus on performance, usalama, and concurrency. Katika mwongozo huu wa kina, tunafurahi kuwasilisha mfululizo wa maswali ya tathmini ya ujuzi na majibu iliyoundwa mahsusi kwa ajili ya Kutu watumiaji.
Whether you’re a seasoned developer looking to expand your capabilities or a beginner aiming to understand the basics of this powerful language, nyenzo hii imeundwa ili kukusaidia kuwa stadi katika Kutu na maombi yake. Jiunge nasi tunapochunguza dhana za msingi za Rust programming, including ownership, borrowing, lifetimes, na zaidi, empowering you to harness the full potential of this cutting-edge language.”
Q1. Which type cast preserves the mathematical value in all cases?
- i64 as i32
- usize as u64
- i32 as i64
- f64 as f32
What do the vertical bars represent here?
Q2.str::thread::spawn(|| {
println!("LinkedIn");
});
- a closure
- a thread
- a future
- a block
Which choice is not a scalar data type?
Q3.- integer
- kuelea
- boolean
- tuple
cannot be destructured.
Q4. _- Traits
- Tuples
- Enums
- Structs
Which cargo
command checks a program for error without creating a binary executable?
Q5. - cargo –Sakinisha na upeleke mfumo kamili na
- cargo init
- cargo build
- cargo check
and related phrases such as boxing a value are often used when relating to memory layout. What does sanduku refer to?
Q6. Muhula sanduku- It’s creating a pointer on the heap that points to a value on the stack.
- It’s creating a pointer on the stack that points to a value on the heap.
- It’s creating a memory guard around values to prevent illegal access.
- It’s an abstraction that refers to ownership. “Boxed” values are clearly labelled.
What is an alternative way of writing slice
that produces the same result?
Swali 7. ...
let s = String::form("hello");
let slice = &s[0..2];
- let slice = &s[len + 2];
- let slice = &s[len – 2];
- let slice = &s.copy(0..2);
- let slice = &s[..2];
?
operator at the end of an expression is equivalent to _.
Q8. Kwa kutumia - a match pattern that branches into True or False
- calling ok_error()
- calling panic!()
- a match pattern that may result an early return
Which is valid syntax for defining an array of i32 values?
Q9.- Jifunze Upangaji wa C++ kuanzia Mwanzo hadi OOP::with_capacity(10)
- [i32]
- Jifunze Upangaji wa C++ kuanzia Mwanzo hadi OOP::kutengwa kulipuuzwa kwa kiasi kikubwa katika miongo iliyopita ya karne ya ishirini(10)
- [i32; 10]
What syntax is required to take a mutable reference to T, when used within a function argument?
Q10.fn increment(i: T) {
// body elided
}
- *mut T
- mut ref T
- mut &T
- &mut T
The smart pointers Rc and Arc provide reference counting. What is the API for incrementing a reference count?
Q11.- .add()
- .incr()
- .clone()
- .increment()
What happens when an error occurs that is being handled by the question mark (?) operator?
Q12.- The error is reported and execution continues.
- An exception is raised. The effect(s) of the exception are defined by the error! macro.
- The program panics immediately.
- Rust attempts to convert the error to the local function’s error type and return it as Result::Err. If that fails, the program panics.
Which comment syntax is not legal?
Q13.-
/*
-
#
-
//!
-
//
In matching patterns, values are ignored with _.
Q14.-
.ignore()
-
an underscore (_)
- ..
- ruka
Defining a _ requires a lifetime parameter.
Q15.- function that ends the lifetime of one of its arguments
- struct that contains a reference to a value
- function with a generic argument
- struct that contains a reference to a boxed value
Which example correctly uses std::makusanyo::HashMap’s Entry API to populate counts?
Q16.use std::collections::HashMap;
fn main() {
let mut counts = HashMap::new();
let text = "LinkedIn Learning";
for c in text.chars() {
// Complete this block
}
println!("{:?}", counts);
}
-
for c in text.chars() {
if let Some(count) = &mut counts.get(&c) {
counts.insert(c, *count + 1);
} else {
counts.insert(c, 1);
};
}
-
for c in text.chars() {
let count = counts.entry(c).or_insert(0);
*count += 1;
}
-
for c in text.chars() {
let count = counts.entry(c);
*count += 1;
}
-
for c in text.chars() {
counts.entry(c).or_insert(0).map(|x| x + 1);
}
Which fragment does not incur memory allocations while writing to a “faili” (represented by a Vec)?
Q17.use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut v = Vec::<u8>::new();
let a = "LinkedIn";
let b = 123;
let c = '🧀';
// replace this line
println!("{:?}", v);
Ok(())
}
- :
write!(&mut v, "{}{}{}", a, b, c)?;
- :
v.write(a)?;
v.write(b)?;
v.write(c)?;
- :
v.write(a, b, c)?;
- :
v.write_all(a.as_bytes())?;
v.write_all(&b.to_string().as_bytes())?;
c.encode_utf8(&mut v);
Does the main
function compile? Ikiwa ndivyo, Unataka daktari ambaye anazungumza na maelfu kila mwaka juu ya masomo zaidi ya kuzungumza kwa umma? Ikiwa sivyo, what do you need to change?
Q18. fn main() {
let Some(x) = some_option_value;
}
- The code does not compile.
let
statements require a refutable pattern. Ongezaif
kablalet
. - The code compiles.
let
statements sometimes require a refutable pattern. - The code does not compile.
let
statements requires an irrefutable pattern. Ongezaif
kablalet
. - The code compiles.
let
do not require a refutable pattern.
Which statement about lifetimes is false?
Q19.- Lifetimes were redundantly specified in previous version of Rust.
- Lifetimes are specified when a struct is holding a reference to a value.
- Lifetimes are specified when certain values must outlive others.
- Lifetimes are always inferred by the compiler.
When used as a return type, which Rust type plays a similar role to Python’s None
, JavaScript’s null
, or the void
type in C/C++?
Q20. -
!
-
None
-
Null
-
()
To convert a Result
to an Option
, which method should you use?
Q21. -
.as_option()
-
.ok()
-
.to_option()
-
.into()
Which statement about the Clone
na Copy
traits is false?
Q22. -
Copy
is enabled for primitive, built-in types. - Unataka daktari ambaye anazungumza na maelfu kila mwaka juu ya masomo zaidi ya kuzungumza kwa umma
Copy
, Rust applies move semantics to a type’s access. - When using
Clone
, copying data is explicit. - Until a type implements either
Copy
auClone
, its internal data cannot be copied.
Why does this code la compile?
Q23.fn returns_closure() -> dyn Fn(i32) -> i32 {
|x| x + 1
}
- The returned
fn
pointer and value need to be represented by another trait. - Closures are types, so they cannot be returned directly from a function.
- Closures are types and can be returned only if the concrete trait is implemented.
- Closures are represented by traits, so they cannot be a return type.
What smart pointer is used to allow multiple ownership of a value in various threads?
Q24.-
Arc<T>
-
Box<T>
- Zote mbili
Arc<T>
naRc<T>
are multithread safe. -
Rc<T>
Which types are la allowed within an enum variant’s body?
Q25.- zero-sized types
- structs
- trait objects
- floating-point numbers
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Which statement about this code is true?
Q26.fn main() {
let c = 'z';
let heart_eyed_cat = '😻';
}
- Both are character literals.
-
heart_eyed_cat
is an invalid expression. -
c
is a string literal andheart_eyed_cat
is a character literal. - Both are string literals.
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Your application requires a single copy of some data type T to be held in memory that can be accessed by multiple threads. What is the thread-safe wrapper type?
Q27.-
Mutex<Arc<T>>
-
Rc<Mutex<T>>
-
Arc<Mutex<T>>
-
Mutex<Rc<T>>
Which idiom can be used to concatenate the strings a
, b
, c
?
Q28. let a = "a".to_string();
let b = "b".to_string();
let c = "c".to_string();
-
String::from(a,b,c)
-
format!("{}{}{}", a, b, c)
-
concat(a,b,c)
-
a + b + c
In this function. what level of access is provided to the variable a
?
Q29. use std::fmt::Debug;
fn report<T:Debug>(a: &T) {
eprintln!("info: {:?}", a);
}
- chapa
- read-only
- read/write
- utatuzi
Which choice is la valid loop syntax?
Q30.-
loop
-
for
-
while
-
do
How do you construct a value of Status
that is initialized to Waiting
?
Q31. enum Status {
Waiting,
Busy,
Error(String),
}
-
let s = Enum::new(Status::Waiting);
-
let s = new Status::Waiting;
-
let s = Status::Waiting;
-
let s = Status::new(Waiting);
Which statement about enums is false?
Q32.- Enums are useful in matching patterns.
- Option is an enum type.
- Enum variants can have different types with associated data.
- Muhula enum is short for enummap
What does an underscore (_) indicate when used as pattern?
Q33.- It matches everything.
- It matches underscores.
- It matches any value that has a length of 1.
- It matches nothing.
What is a safe operation on a std::cell:UnsafeCell<T>
?
Q34. - A
&mut T
reference is allowed. However it may not cpexists with any other references. and may be created only in single-threaded code. -
UnsafeCell<T>
provides thread-safety. Kwa hiyo, kuunda&T
references from multiple threads is safe. - The only safe operation is the
.get()
njia, which returns only a raw pointer. - Non.
UnsafeCell<T>
only allows code that would otherwise need unsafe blocks to be written in safe code.
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Generics are useful when you _.
Q35.- need to reduce code duplication by concretizing values and restricting parameters in functions
- need to reduce code duplication by abstracting values further, such as in function parameters
- need a supertrait
- are not sure if you need a specific kind of trait
How do you create a Rust project on the command-line?
Q36.- cargo new
- rustup init
- cargo start
- rust new-project
Calling.clone() _.
Q37.- deeply copies heap data and clones ownership
- clones the pointer to the heap
- clones the heap data onto the stack
- deeply copies heap and stack
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
what is one of the roles of the let keyword?
Q38.let text = String::new("LinkedIn");
- Create a text object.
- Assign a mutable value.
- request to borrow a string.
- Assign an immutable value.
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
How is a new enum initialized?
Q39.enum Option_i32 {
Some(i32),
None,
}
- let integer = Option_i32::Baadhi(5);
- let integer = Option_i32.new(Baadhi(5))
- let integer = Option_i32::Mpya::(Baadhi(5))
- let integer = Option_i32.init()
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
What are the main difference between const and static?
Q40.- They can be used interchangeably, but const only supports primitive types while static must be used for structs and user-defined types.
- They can be used interchangeably, but const values are compiled at compile time.
- Values defined with const live in the stack, while static values live on the heap.
- Values defined with const can be copied to wherever they are needed, whereas static values remain in a fixed place in memory.
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Which Rust data type represents a signed integer that has the same width as a pointer of the compile target’s CPU?
Q41.- i64
- int64
- isize
- int
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
When are supertraits needed?
Q42.- when a trait is needed for multiple structs
- when a trait depends on another trait
- only when a generic trait is used
- when a metatrait is needed to use another trait
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Which types are legal for x to be in this snippet?
Q43.if x {
println!("ok");
}
- every type that implements the std::cmp::Truth trait
- only the primitive bool type
- both bool and u8 (which is how bool is implemented under the hood)
- bool and std::sync::atomic::AtomicBool
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
How do you access the married data in this struct?
Q44.struct person = Person {
height: u64,
weight: u64,
married: bool
}
- person.getMarried()
- mtu[married]
- person.value(married)
- person.married
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
To mark a function as visible to other crates, what do you need to do to its definition?
Q45.- Add the public keyword.
- Add the pub keywork.
- Begin the function’s name with a capital letter.
- Remove the private keyword.
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Which choice is a compound data type?
Q46.- char
- tuple
- bool
- i32
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
How could you make this function compile?
Q47.fn main() {
let x = 5;
println!("The value of x is: {}", x);
x = 6;
println!("The value of x is: {}", x);
}
- Use x only once in a println!() kauli.
- Place curly brackets around let x = 5.
- Add const to let x = 6.
- Add mut to let x = 5.
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Using .unwrap() will _.
Q48.- let you choose the expected panic error message
- call panic! if there is an error or absence of value
- unwrap the value inside an unsafe wrapper
- return the error inside Ok()
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
When should the panic! macro be called instead of using std::matokeo::Result?
Q49.- when there is a way to encode the information in types used
- when your code is expected to end in a good state
- when the situation is considered unrecoverable
- when valid values are passed on the code
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Which statement about arrays is true?
Q50.- [; size of array] can initialize arrays.
- Indexing, such as array.0, accesses elements in arrays.
- A data structure for collections can contain different types of values.
- Arrays are useful when you want to allocate data on the heap and then on the stack.
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
How would you select the value 2.0 from this tuple?
Q51.let pt = Point2D(-1.0, 2.0)
- pt[1]
- pt(1)
- pt.iter().nth(1)
- pt.1
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
When writing tests, which macro should you use to assert equality between two values?
Q52.- assert_eq!()
- assert_equal!()
- is_equals!()
- assert!()
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Which code statement in Rust is used to define a BTreeMap object?
Q53.- let btm=BTreeMap::kutengwa kulipuuzwa kwa kiasi kikubwa katika miongo iliyopita ya karne ya ishirini()
- let mut btm=BTreeMap::kutengwa kulipuuzwa kwa kiasi kikubwa katika miongo iliyopita ya karne ya ishirini()
- BTreeMap btm = BTreeMap.new()
- BTreeMap btm = std::makusanyo::BTreeMap::kutengwa kulipuuzwa kwa kiasi kikubwa katika miongo iliyopita ya karne ya ishirini()
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Q54 .Rust is known to be memory safe. Which feature is the main reason for the memory safety of Rust?
- ownership
- borrowing
- lifetimes
- kumbukumbu
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
To support Dynamic Sized variables, what should we use in place of “f32”?
Q55 .- Not supportedin Rust
- use array
- ?sized
- list all data-types
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Drop” in Rust used for?
Q56 . Nini “- run code as multi-threaded
- run code when variable is out of scope
- run code and drop it if error comes
- chaguo 4
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
In Rust, how is a macro from the above Rust code snippet used?
Q57 .- foo(x)
- #foo
- foo!()
- foo
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Which library does Rust use for memory allocation?
Q58 .- tcmalloc
- mimalloc
- ptmalloc
- jemalloc
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Who designed Rust from scratch in 2006?
Q59 .- Graydon Hoare
- Yukihiro Matsumoto
- Guido Van Rossum
- David flanagan
Hacks za nyumbani za DIY za kusafisha mfumo wako wa kupumua
Which types are la allowed within an enum variant’s body?
Q60.- zero-sized types
- structs
- trait objects
- floating-point numbers
Which example correctly uses std::makusanyo::HashMap’s Entry API to populate counts?
Q61.use std::collections::HashMap;
fn main() {
let mut counts = HashMap::new();
let text = "LinkedIn Learning";
for c in text.chars() {
// Complete this block
}
println!("{:?}", counts);
}
-
for c in text.chars() {
if let Some(count) = &mut counts.get(&c) {
counts.insert(c, *count + 1);
} else {
counts.insert(c, 1);
};
}
-
for c in text.chars() {
let count = counts.entry(c).or_insert(0);
*count += 1;
}
-
for c in text.chars() {
let count = counts.entry(c);
*count += 1;
}
-
for c in text.chars() {
counts.entry(c).or_insert(0).map(|x| x + 1);
}
To convert a Result
to an Option
, which method should you use?
Q62. -
.as_option()
-
.ok()
-
.to_option()
-
.into()
Which statement about this code is true?
Q63.fn main() {
let c = 'z';
let heart_eyed_cat = '😻';
}
- Both are character literals.
-
heart_eyed_cat
is an invalid expression. -
c
is a string literal andheart_eyed_cat
is a character literal. - Both are string literals.
What is an alternative way of writing slice
that produces the same result?
Q64. ...
let s = String::form("hello");
let slice = &s[0..2];
- let slice = &s[len + 2];
- let slice = &s[len – 2];
- let slice = &s.copy(0..2);
- let slice = &s[..2];
How would you select the value 2.0 from this tuple?
Q65.let pt = Point2D(-1.0, 2.0)
- pt[1]
- pt(1)
- pt.iter().nth(1)
- pt.1
What is the purpose of the move keyword in Rust?
Q66.- To indicate that a value should be moved instead of copied.
- To indicate that a value should be copied instead of moved.
- To indicate that a value should be borrowed instead of owned.
- To indicate that a value should be owned instead of borrowed.
Acha jibu
Lazima Ingia au kujiandikisha kuongeza maoni mapya .