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
How to read current directory using Readdir?
Cannot convert <type1> to <type2> error in Golang
Go program to find CNAME record of a domain
Undefined reference to <variable/function> error in Golang
Golang program for implementation of Bubble Sort
Interface embedding and calling interface methods from another package in Go (Golang)