【Golang】func & pointer Posted on 2019-09-06 | In Golang kind Different kinds use a pointer to change the value in Func. map slice array string struct 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859package main import "fmt" func main() { // map var mapObj = map[int]string{} mapObj[0] = "max" updateMapObj(mapObj) fmt.Println(" map =>", mapObj) // slice sliceObj := []string{ 0: "max", } updateSliceObj(sliceObj) fmt.Println(" slice =>", sliceObj) // [sunny] // array arrayObject := [1]string{"max"} updateArrayObj(&arrayObject) fmt.Println(" array =>", arrayObject) // [sunny] // string var stringObj string stringObj = "max" updateStringObj(&stringObj) fmt.Println("string =>", stringObj) // 999 // struct var srtuctObj StructObject srtuctObj.name = "max" updateStructObj(&srtuctObj) fmt.Println("struct =>", srtuctObj) // {sunny} } func updateMapObj(mapObj map[int]string) { mapObj[0] = "sunny" } func updateArrayObj(arrayObject *[1]string) { arrayObject[0] = "sunny" } func updateSliceObj(sliceObj []string) { sliceObj[0] = "sunny" } func updateStringObj(stringObj *string) { *stringObj = "sunny" } type StructObject struct { name string } func updateStructObj(srtuctObj *StructObject) { srtuctObj.name = "sunny" }