Javatpoint Logo
Javatpoint Logo

Go Struct

In Go, Struct can be used to create user-defined types.

Struct is a composite type means it can have different properties and each property can have their own type and value.

Struct can represent real-world entity with these properties. We can access a property data as a single entity. It is also valued types and can be constructed with the new() function.

Go Struct Example

Output:

{John Anderson 30}
John

Go Embedded Struct

Struct is a data type and can be used as an anonymous field (having only the type). One struct can be inserted or "embedded" into other struct.

It is a simple 'inheritance' which can be used to implement implementations from other type or types.

Go Embedded Struct Example

Output:

{Raj Kumar}   I am a person
{{John Ponting} 11}  I am a employee

Next TopicGo Interface




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA