Go - Structures
Go arrays assist you to outline variables that may preserve numerous records objects of the same kind. Structure is any other consumer-described information type available in Go programming
Defining a StructureTo define a shape, you must use kind and struct statements. The struct declaration defines a brand new records type, with multiple participants to your software.
kind struct_variable_type struct member definition; member definition; ... Member definition;Once a structure kind is described, it is able to be used to claim variables of that kind the usage of the subsequent syntax
variable_name := structure_variable_type value1, value2...Valuen
Accessing Structure MembersTo access any member of a shape, we use the member get right of entry to operator (.).
package fundamental import "fmt" type School struct age string pupil string difficulty string school_id int func essential() var school1 School /* Declare school1 of kind college */ var school2 School /* Declare school2 of kind faculty */ /* school 1 specification */ school1.Age = "sixteen" school1.Student = "Markup David" school1.Difficulty = "COMPUTER SCIENCE " school1.School_id = 6495407 /* school 2 specification */ school2.Age = "seventeen" school2.Scholar = "Sara" school2.Issue = "ENGLISH" school2.School_id = 6495700 /* print school1 information */ fmt.Printf( "college 1 age : %sn", school1.Age) fmt.Printf( "college 1 student : %sn", school1.Pupil) fmt.Printf( "school 1 problem : %sn", school1.Subject) fmt.Printf( "school 1 school_id : %dn", school1.School_id) /* print school2 data */ fmt.Printf( "school 2 age : %sn", school2.Age) fmt.Printf( "college 2 scholar : %sn", school2.Student) fmt.Printf( "faculty 2 issue : %sn", school2.Problem) fmt.Printf( "faculty 2 school_id : %dn", school2.School_id)When the above code is compiled and performed, it produces the following end result
school 1 age : sixteen college 1 student : Markup David college 1 problem : COMPUTER SCIENCE college 1 school_id : 6495407 faculty 2 age : seventeen school 2 student : Sara school 2 difficulty : ENGLISH college 2 school_id : 6495700
Pointers to StructuresYou can define tips to structures inside the same manner as you define pointer to some other variable as follows
var struct_pointer *Booksyou could store the address of a structure variable in the above defined pointer variable. To discover the cope with of a shape variable