pointer
Chapter around the strings, numbers, arrays, slices, map, channel, and the structure and the function pointer assignment of the transmission parameter analysis application
String
The string itself is StringHeader structure comprising a pointer to the Data string length, the following
type StringHeader struct { Data uintptr Len int }
Data at the memory address can not be changed, the string and pass parameters only copy assignment value and the Data Len of StringHeader
main Package Import "FMT" FUNC main () { str: "! the Hello World" = var data String data = str // str copy of the Data Len fmt.Println (data) data = "! Go the Hello" // Modify data generating a new value StringHeader structure in memory and assigned to Data fmt.Println (Data) // STR memory unchanged fmt.Println (STR) } // the Hello World! // Go the Hello! // the Hello World!
When the string pointer variable is declared, when an object must be a string variable assignment memory address, the function is passed the parameter copy-only memory address
main Package Import "FMT" FUNC main () { str: "! the Hello World" = var PTR String * // str error method is a string of non-pointer type // str PTR = // str correctly acquired address is assigned to ptr ptr = & str fmt.Println (ptr) fmt.Println (* ptr) } // 0xc0000421c0 // the Hello World!