Go Structs (Part 2) — Zero Value Structs

A zero value struct is simply a struct variable where each key’s value is set to their respective zero value.

This article is part of the Structs in Go series.

We can create a zero value struct using the var statement to initialize our struct variable.

Image for post
Image for post

Line 15: This initializes a zero value struct variable. You can also write this line as dave := employee{}

Line 17: Primitive data types defaults to their respective zero values. For int, that is 0, and strings that it is an empty string (hence the big black space in the out put), and for booleans it is false.

Line 18: You can replace zero values with your own values.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store