Can You Do Pointer Arithmetic in Go

Go forbids direct pointer arithmetic for safety, requiring the unsafe package for manual memory offset calculations.

No, you cannot perform pointer arithmetic directly on Go pointers. Go forbids adding integers to pointers or subtracting pointers from each other to prevent unsafe memory access. To achieve similar results, you must use the unsafe package to convert pointers to uintptr integers, perform the math, and convert back, though this is generally discouraged for safety reasons.

import "unsafe"

func addPointer(p unsafe.Pointer, offset uintptr) unsafe.Pointer {
    return unsafe.Pointer(uintptr(p) + offset)
}