Zero value in Golang Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In Go language, whenever we allocate memory for a variable with the help of declaration or by using new and if the variable is not initialized explicitly, then the value of such types of variables are automatically initialized with their zero value. The initialization of the zero value is done recursively. So, every element of the array of the structs has its fields zero if they are not specified with any value. Following are the zero values for different types of variables: Type Zero Value Integer 0 Floating point 0.0 Boolean false String "" Pointer nil Interface nil Slice nil Map nil Channel nil Function nil Example 1: C // Go program to illustrate the concept of zero value package main import "fmt" // Main Method func main() { // Creating variables // of different types var q1 int var q2 float64 var q3 bool var q4 string var q5 []int var q6 *int var q7 map[int]string // Displaying the zero value // of the above variables fmt.Println("Zero value for integer types: ", q1) fmt.Println("Zero value for float64 types: ", q2) fmt.Println("Zero value for boolean types: ", q3) fmt.Println("Zero value for string types: ", q4) fmt.Println("Zero value for slice types: ", q5) fmt.Println("Zero value for pointer types: ", q6) fmt.Println("Zero value for map types: ", q7) } Output: Zero value for integer types: 0 Zero value for float64 types: 0 Zero value for boolean types: false Zero value for string types: Zero value for slice types: [] Zero value for pointer types: <nil> Zero value for map types: map[] Example 2: C // Go program to check the variable // contains zero value or not package main import "fmt" func main() { // Creating variables of different types var q1 int = 2 var q2 float64 var q3 bool var q4 string // Slice var q5 []int // Pointer var q6 *int // Map var q7 map[int]string // Checking if the given variables // contain their zero value or not if q1 == 0 { fmt.Println("True") } else { fmt.Println("False") } if q2 == 0 { fmt.Println("True") } else { fmt.Println("False") } if q3 == false { fmt.Println("True") } else { fmt.Println("False") } if q4 == "" { fmt.Println("True") } else { fmt.Println("False") } if q5 == nil { fmt.Println("True") } else { fmt.Println("False") } if q6 == nil { fmt.Println("True") } else { fmt.Println("False") } if q7 == nil { fmt.Println("True") } else { fmt.Println("False") } } Output: False True True True True True True Comment More infoAdvertise with us Next Article Packages in Golang A ankita_saini Follow Improve Article Tags : Go Language Golang Similar Reads Reflection in Golang Reflection is the ability of a program to introspect and analyze its structure during run-time. In Go language, reflection is primarily carried out with types. The reflect package offers all the required APIs/Methods for this purpose. Reflection is often termed as a method of metaprogramming. To und 6 min read string package in Golang Go language provides a string package that holds different types of functions to manipulate UTF-8 encoded strings. To access the function of the string package you need to import a string package in your program with the help of the import keyword.  FunctionDescriptionfunc CompareThis function is u 8 min read Packages in Golang Packages are the most powerful part of the Go language. The purpose of a package is to design and maintain a large number of programs by grouping related features together into single units so that they can be easy to maintain and understand and independent of the other package programs. This modula 5 min read fmt Package in GoLang Prerequisite: Packages in GoLang and Import in GoLang Technically defining, a package is essentially a container of source code for some specific purpose. Packages are very essential as in all programs ranging from the most basic programs to high-level complex codes, these are used. A package ensur 13 min read Strings in Golang In the Go language, strings are different from other languages like Java, C++, Python, etc. It is a sequence of variable-width characters where every character is represented by one or more bytes using UTF-8 Encoding. In other words, strings are the immutable chain of arbitrary bytes(including bytes 7 min read bits Package in Golang Go language provides inbuilt support for bit counting and manipulation functions for the predeclared unsigned integer types with the help of the bits package. .bits-package-Golang-table { border-collapse: collapse; width: 100%; } .bits-package-Golang-table td { border: 1px solid #5fb962; text-align: 6 min read Like