-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointers.fx
More file actions
36 lines (27 loc) · 877 Bytes
/
Copy pathpointers.fx
File metadata and controls
36 lines (27 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#import "standard.fx";
using standard::io::console;
def main() -> int
{
uint x, y = 10, 0;
uint* px, py = @x, @y;
// A pointer is simply a variable and its value is an address
// An address is a number.
// Therefore, we can store that address
//
u64 kx = px;
// (@) is address-cast. It reinterprets the number as an address
// When we treat a number as an address, we call that a pointer.
// Therefore, we can assign this to another pointer.
//
py = (@)kx;
// py now points to x
// Dereference py to get the value at the address
// Cast to make sure it's the proper type to print
if (x == 10 & y == 0 & *py == x & px == py & px == (@)kx)
{
print("Success, y unchanged, py points to x.\n\0");
print((uint)*py);
return 0;
};
return 0;
};