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.go170 chars14 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.
gistlibby LogSnag