0
我是新来的,请原谅我,如果这是一个常规问题,那么如何赋值给字符串解引用操作符在下面工作?将值赋给字符串解引用操作符
package main
import "fmt"
func main() {
course := "Docker Deep Dive"
changeCourse(&course)
}
func changeCourse(course *string) {
fmt.Println(course) // prints the memory address of course since it is a pointer
fmt.Println(*course) // prints the value since * is dereferenceing the pointer
// Issue
*course = "Docker Extended" // *course is a string, how does the assignment works here.
fmt.Println(*course) // prints "Docker Extended"
}
简言之,deference返回一个变量,以便我们可以访问和分配值? @Tinwor –
简单地说,间接运算符返回变量的值,而引用运算符返回变量的地址。在Go中,您还可以使用新的内置函数来获取指针。 @SrinivasDamam – Tinwor
谢谢,这明确表示。 –