Struct Instantiation Using Pointer Address Operator
Creates an instance of rectangle struct by using a pointer address operator is denoted by & symbol.
Example
package main
import "fmt"
type rectangle struct {
length int
breadth int
color string
}
func main() {
var rect1 = &rectangle{10, 20, "Green"} // Can't skip any value
fmt.Println(rect1)
var rect2 = &rectangle{}
rect2.length = 10
rect2.color = "Red"
fmt.Println(rect2) // breadth skipped
var rect3 = &rectangle{}
(*rect3).breadth = 10
(*rect3).color = "Blue"
fmt.Println(rect3) // length skipped
}
Most Helpful This Week
Goroutines Channels order of execution
How do you handle HTTP server HTTP/2 in Go?
Web Application to Get Trending Hashtags Near a Location
GO Program to Swap Number Without Using Temporary Variables
Golang program for implementation of Tower of Hanoi Algorithm
How do you send an HTTP POST request with an HTTP client in Go?