<i32 Part>
[예제 코드_1]
fn main() {
let age: i32 = 25;
do_something(age);
}
fn do_something(age: i32) {
println!("Hello, {}", age);
}
[실행 결과]
Hello, 25!
[예제 코드_2]
fn main() {
let age: i32 = 25;
do_something(age);
println!("{}", age);
}
fn do_something(age: i32) {
println!("Hello, {}", age);
}
[실행 결과]
Hello, 25!
25
[예제 코드_3]
fn main() {
let age: i32 = 25;
do_something(&age);
println!("{}", age);
}
fn do_something(age: &i32) {
println!("Hello, {}", age);
}
[실행 결과]
Hello, 25!
25
[예제 코드_4]
fn main() {
let age: i32 = 25;
do_something(age.clone());
println!("{}", age);
}
fn do_something(age: i32) {
println!("Hello, {}!", age);
}
[실행 결과]
Hello, 25!
25
<참조 1> https://itnext.io/rust-ownership-50-code-examples-96203fcf79ea
<참조 2>
'Rust' 카테고리의 다른 글
[Rust] Ownership(소유권) 기초 예제 : Vec<String> (34일차) (0) | 2023.01.16 |
---|---|
[Rust] Ownership(소유권) 기초 예제 : Struct (33일차) (0) | 2023.01.15 |
[Rust] Ownership(소유권) 기초 예제 : String (31일차) (0) | 2023.01.13 |
[Rust] Iterator 예제 (30일차) (0) | 2023.01.12 |
댓글