VOOZH about

URL: https://www.geeksforgeeks.org/go-language/how-to-assign-default-value-for-struct-field-in-golang/

⇱ How to Assign Default Value for Struct Field in Golang? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Assign Default Value for Struct Field in Golang?

Last Updated : 22 Jun, 2020
Default values can be assigned to a struct by using a constructor function. Rather than creating a structure directly, we can use a constructor to assign custom default values to all or some of its members. Example 1: Output:
{Vani 0 0}
{Vani 40 18}
{ABC 78 19}
Another way of assigning default values to structs is by using tags. Tags can only be used for string values only and can be implemented by using single quotes(''). Example 2: Output:
Default name is: geek
Comment
Article Tags:

Explore