This article describes the usage of new functions in Go language. Share it for your reference. The details are as follows:
The expression new(T) assigns a zero-initialized T value and returns a pointer to it.
var t *T = new(T)
or
t := new(T)
The code is as follows:
Copy the codeThe code is as follows:
package main
import "fmt"
type Vertex struct {
X, Y int
}
func main() {
v := new(Vertex)
(v)
, = 11, 9
(v)
}
import "fmt"
type Vertex struct {
X, Y int
}
func main() {
v := new(Vertex)
(v)
, = 11, 9
(v)
}
I hope this article will be helpful to everyone's Go language programming.