What Do * and & Mean in Go

In Go, * dereferences a pointer to access its value, while & takes the memory address of a variable.

In Go, * declares a pointer type or dereferences a pointer, while & takes the memory address of a variable. Use * to access the value stored at an address and & to get the address of a variable for passing by reference.

x := 10
p := &x    // p holds the address of x
fmt.Println(*p) // prints 10 (value at address p)
*p = 20    // changes x to 20
fmt.Println(x)  // prints 20