Junior — Middle
Kas saaksite selgitada, kuidas programmeerimises on rea struktuur rakendatud ja millest see koosneb?
sobes.tech AI
Vastus AI-lt
In Go, a string (string) is an immutable sequence of bytes, typically representing text in UTF-8 encoding. Internally, a string is implemented as a structure with two fields: a pointer to a byte array and a length.
Example of a simplified string structure in Go:
// stringHeader — internal string structure
import "reflect"
var s string = "hello"
header := (*reflect.StringHeader)(unsafe.Pointer(&s))
// header.Data — pointer to bytes
// header.Len — length of the string
Strings in Go are immutable, so any operation that modifies the string creates a new copy.