Middle
What is a pointer and how much does it weigh?
sobes.tech AI
Answer from AI
A pointer in Go is a variable that stores the address of another variable in memory. It allows working directly with data by address, which is useful for optimization and passing large structures without copying.
The size of a pointer depends on the platform architecture: on 32-bit systems, a pointer occupies 4 bytes, and on 64-bit systems, it occupies 8 bytes.
Example of using a pointer:
var a int = 42
var p *int = &a // p stores the address of variable a
fmt.Println(*p) // dereferencing the pointer, outputs 42