Convert between pointer types in Go by casting through unsafe.Pointer to bypass type safety.
Use unsafe.Pointer as an intermediate type to convert between incompatible pointer types, bypassing Go's type safety checks.
import "unsafe"
// Convert *int to *byte
var pInt *int
var pByte *byte = (*byte)(unsafe.Pointer(pInt))
// Convert *byte back to *int
var pInt2 *int = (*int)(unsafe.Pointer(pByte))
Converting between pointer types with unsafe forces Go to treat the memory address of one variable as if it were a different type. It is like telling the computer to read the same house number but interpret the contents as a different kind of furniture. Use this only when you are absolutely sure the memory layout matches, as it can cause crashes if done incorrectly.