Learn Before
Code
Example of Immutable Reference - Rust Programming
fn main() { let s1 = String::from("hello"); // Pass an immutable reference to the function let len = calculate_length(&s1); println!("The length of '{}' is {}.", s1, len); } fn calculate_length(s: &String) -> usize { s.len() } // s goes out of scope, but since // it's a reference, nothing is freed
0
1
Updated 2023-04-19
Tags
Object-Oriented Programming
Programming Language Paradigms
General programming languages
Computing Sciences