what's the issue? ` number := 0 add10(number) fmt.println(number) // logs 0 } func add10(number int) { number = number + 10 }` in go

In Go, parameters are passed by value. So when you pass number to the add10 function, a copy of the value is created. Therefore, any changes made to number inside the add10 function will not affect the original value.

If you want to modify the original number variable, you can pass it as a pointer. Here's an example:

main.go
package main

import "fmt"

func main() {
    number := 0
    add10(&number)
    fmt.Println(number) // logs 10
}

func add10(number *int) {
    *number = *number + 10
}
170 chars
14 lines

By using a pointer to number, any changes made inside the add10 function will affect the original variable. Note that when accessing or modifying the value of the pointer, we use the * operator.

related categories

gistlibby LogSnag