Programming Languages Rust Subjective
Oct 04, 2025

How do you declare variables and functions in Rust?

Detailed Explanation
Variable and function declaration in Rust: • Variables: let keyword (immutable by default) • Mutable variables: let mut keyword • Constants: const keyword • Functions: fn keyword Examples: // Variables let x = 5; // immutable let mut y = 10; // mutable const MAX: u32 = 100; // constant // Functions fn greet(name: &str) -> String { format!("Hello, {}!", name) } fn add(a: i32, b: i32) -> i32 { a + b // implicit return }
Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback