

Default zero values for all Go types
source link: https://yourbasic.org/golang/default-zero-value/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Default zero values for all Go types

Variables declared without an initial value are set to their zero values:
0
for all integer types,0.0
for floating point numbers,false
for booleans,""
for strings,nil
for interfaces, slices, channels, maps, pointers and functions.
The elements of an array or struct will have its fields zeroed if no value is specified. This initialization is done recursively:
type T struct {
n int
f float64
next *T
}
fmt.Println([2]T{}) // [{0 0 <nil>} {0 0 <nil>}]
Further reading
Struct initialization code example
Share:
Recommend
-
126
There are already multiple articles and sources about using Kotlin and JSON. First of, there is the Awesome-Kotlin list about JSON libraries. Then, there are multiple articles like this one, talking…
-
71
As you might’ve noticed from other blog post entries I’m suddenly all intodirectory services. This happens b/c that’s what I’m currently working on...
-
28
How the way you define your hash default value can generate side effects in your program?
-
12
Inserting JSON Data with Default Values in PostgreSQL 2020-04-02 (posted in blog) So you have a table, and you have some JSON data you want to insert into that table, but the JSON either cont...
-
14
Parse parameter default values using PowerShell – Part 3 In part 1 and
-
7
Parse parameter default values using PowerShell – Part 2 In my last post, I showed how to use TSqlParser
-
10
Swift Associated Types With Default Values Swift Associated Types With Default Values September 16, 2018 I was browsing the Swift...
-
23
Optional parameters, default parameter values and method overloading yourbasic.org/golang
-
6
Parse parameter default values using PowerShell – Part 1 If you have ever tried to determine the default values for stored procedure parameters, you probably have marks on your forehead from hi...
-
6
Why and how to use Ruby’s Hash#fetch for default values – avdi.codes
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK