how to pass struct value to function as reference
https://doc.rust-lang.org/book/ch03-03-how-functions-work.html
You can pass struct values to functions in the same way as any other value.
What are you trying to do?
thanks i got it
//my code
struct Dimention
{
l:usize,
b:usize,
h:usize
}
fn main()
{
let mut measure:Dimention = Dimention{l:0,b:0,h:0};
println!("{} {} {}",measure.l,measure.b,measure.h);
struct_funtion( &mut measure.l,&mut measure.b, &mut measure.h);
println!("{} {} {}",measure.l,measure.b,measure.h);
}
fn struct_funtion(l:&mut usize,b:&mut usize,h:&mut usize)
{
*l=10;
*b=20;
*h=20;
}
Please use code fences when writing out code here like this,
```rust
// your code here
```
struct Dimention {
l: usize,
b: usize,
h: usize
}
fn main() {
let mut measure:Dimention = Dimention{l:0,b:0,h:0};
println!("{} {} {}",measure.l,measure.b,measure.h);
struct_funtion(&mut measure);
println!("{} {} {}",measure.l,measure.b,measure.h);
}
fn struct_funtion(dim: &mut Dimention) {
dim.l=10;
dim.b=20;
dim.h=20;
}
thanks for the tip
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.