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
Golang read file line by line to string
GO Program to print full Pyramid using *
How to copy one slice items into another slice in Golang?
How do you handle HTTP authentication with an HTTP client in Go?
GO Program to Find LCM and GCD of given two numbers
Golang program for implementation of Floyd–Warshall Algorithm
Database as a Service (DBaaS): Simplifying Database Management in the Cloud
How to write backslash in Golang string?
State and Props in React
Contains, ContainsAny, Count and EqualFold string functions in Go Language