Files
compiler-old/tests/struct_pointers.test
T

38 lines
545 B
Plaintext

[code]
foreign fn putchar(c: i32) -> i32;
struct Rect {
width: i32,
height: i32
}
fn modify_rect(r: *Rect) {
let temp: Rect = *r;
temp.width = temp.width + 10;
temp.height = temp.height + 20;
*r = temp;
}
fn print_num(n: i32) {
putchar(48 + (n / 10));
putchar(48 + (n % 10));
putchar(10);
}
fn main() -> i32 {
let r = Rect { width: 15, height: 25 };
modify_rect(&r);
print_num(r.width);
print_num(r.height);
return 0;
}
[expected_return_code]
0
[expected_output]
25
45