Sobes.tech
Junior — Middle

Kas keel Go toetab näidete arvutamist?

sobes.tech AI

Vastus AI-lt

In the Go language, arithmetic operations with pointers are not directly supported, as in C or C++. Go allows pointer arithmetic only in limited cases, such as when working with slices and arrays through indexing. This is done to enhance safety and prevent memory errors. For example, you cannot simply add a number to a pointer to get the next element, but you can use slice indexing:

arr := []int{10, 20, 30}
ptr := &arr[0]
// You cannot do ptr + 1, but you can access arr[1]
fmt.Println(arr[1]) // 20

Thus, Go restricts pointer arithmetic to avoid unsafe operations.