init
This commit is contained in:
@@ -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^)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user