feat: pointers, runes, structs

This commit is contained in:
2026-03-02 09:40:31 +01:00
parent 19516beeaa
commit e606e97045
3 changed files with 108 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package main
import "fmt"
// This functions creates a copy of the argument and does not change the original
func zeroval(ival int) {
ival = 0
}
// Changes the value of the argument because it is a pointer.
func zeroptr(iptr *int) {
*iptr = 0
}
func main() {
i := 1
fmt.Println("initial", i)
zeroval(i)
fmt.Println("zeroval", i)
// & operand means the address of the variable. Creates a pointer when a function needs that as argument
zeroptr(&i)
fmt.Println("zeroptr:", i)
fmt.Println("Poiner:", &i)
}