This commit is contained in:
Eric Christensen
2026-07-30 09:05:56 -07:00
commit b83336f7e3
2 changed files with 64 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
package main
import "core:fmt"
five: int = 5
six: int = 6
foo :: proc(p: ^int) {
fmt.println("p memory address: ", p)
fmt.println("value of p: ", p^)
p = &six
// p DROPPED here
// a in main() is not changed
}
bar :: proc(pp: ^^int) {
fmt.println("pp memory address: ", pp)
fmt.println("pp memory address deferenced: ", pp^)
pp^ = &six
// pp DROPPED here
}
dez :: proc() -> ^int {
return &six
}
main :: proc() {
fmt.println("memory space of 5: ", &five)
fmt.println("memory space of 6: ", &six)
a := &five
// YOU CAN'T CALL FOO
// fmt.println("~~~~~~~~~~~~~~~~~~~~~~~~\n")
// fmt.println("CALL TO FOO WITH PARAM P")
// fmt.println("a memory address: ", a)
// foo(a)
// fmt.println("a memory address: ", a)
fmt.println("~~~~~~~~~~~~~~~~~~~~~~~~\n")
fmt.println("CALL TO BAR WITH PARAM PP")
fmt.println("a memory address: ", a)
bar(&a)
fmt.println("a memory address: ", a)
fmt.println("value of a: ", a^)
fmt.println("~~~~~~~~~~~~~~~~~~~~~~~~\n")
b := &five
fmt.println("b memory space and value", b, b^)
b = dez()
fmt.println("b memory space and value", b, b^)
}