Zero Values

  • When a variable is declared and it isn’t assigned any value at the time of declaration, Go will assign a zero value to it based on it’s variable type.

  • Type of a variable decides what a zero value to it will take initially when declared (and if it isn’t assigned any value at the time of declaration).

    // Zero Values assigned to variables by Go when they are declared and not assigned any values at the time of declaration.
    var adiBool bool          // false
    var adiInt int            // 0
    var adiFloat float64      // 0
    var adiStr string         // ""
    var adiPointer *string    // nil | 'nil' means it doesn't point to any memory location
    

See also