Declaration of a struct type


A struct type rectangle is declared that has three data fields of different data-types. Here, struct used without instantiate a new instance of that type.

Example

package main
 
import "fmt"
 
type rectangle struct {
	length  float64
	breadth float64
	color   string
}
 
func main() {
	fmt.Println(rectangle{10.5, 25.10, "red"})
}

The rectangle struct and its fields are not exported to other packages because identifiers are started with an lowercase letter. In Golang, identifiers are exported to other packages if the name starts with an uppercase letter, otherwise the accessibility will be limited within the package only.

Most Helpful This Week