“Pergi pointer” Kode Jawaban

Pergi pointer

p := Vertex{1, 2}  // p is a Vertex
q := &p            // q is a pointer to a Vertex
r := &Vertex{1, 2} // r is also a pointer to a Vertex

// The type of a pointer to a Vertex is *Vertex

var s *Vertex = new(Vertex) // new creates a pointer to a new struct instance
DevLorenzo

Pergi pointer

&	address of / create pointer
*	dereference pointer
DevLorenzo

Pergi pointer

func main() {
	i, j := 42, 2701

	p := &i         // point to i
	fmt.Println(*p) // read i through the pointer
	*p = 21         // set i through the pointer
	fmt.Println(i)  // see the new value of i

	p = &j         // point to j
	*p = *p / 37   // divide j through the pointer
	fmt.Println(j) // see the new value of j
}
DevLorenzo

Jawaban yang mirip dengan “Pergi pointer”

Pertanyaan yang mirip dengan “Pergi pointer”

Lebih banyak jawaban terkait untuk “Pergi pointer” di Go

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya