When a variable is declared, it automatically contains a default value of zero or null for its type: 0 for int , 0.0 for float , false for bool , empty string for string , nil for pointer, null structure, etc.
All memory in Go is initialized!
For example: var arr [5]int in memory can be visualized as:
+---+---+---+---+ | | | | | +---+---+---+---+ 0 1 2 3
When declaring an array, each element in it is automatically initialized with a zero default value for this type, here all elements by default are 0.
Therefore, it is advisable to initialize without a default value, in other cases than situations where you explicitly want to declare a variable with a default value.
Simo endre
source share