In the diagram below shows some Go codes, we create a pointer var p *int32 = new(int32) and perform Pointer Dereference with *p
Memory efficiency
Pass data to functions by pointer is memory-efficient. The data we pass into a function is basically a Memory Address to access that block of data. If we pass data into functions without pointer. We need to create an entire duplicate of data and pass it to the functions.
In Java, data is passed to functions by pointer by default. However in Go, we need to explicity specify the pointer datatype for the function input, then we can pass data by point!
Pointer is the usual way of accessing hardware.
More power!
Function scope rules prevent a function call from directly modifying variables outside its own scope. However, using pointers allows you to pass memory addresses to a function, enabling changes made within the function to affect variables outside its scope.
When *n is uninitialised, *n = 123; will attempt to write the value 123 into a random memory address that *n might be pointing to. This memory address may not be accessible to your program, which will trigger a segmentation fault.