How do you express a "null" value in Go?

Go

Go Problem Overview


How do you express a "null" value in Go?

type Node struct { 
	next *Node
	data interface{}
}

And I want to say

return &Node{ data: NULL, next: NULL }

Go Solutions


Solution 1 - Go

The equivalent of NULL is nil, as you already discovered. Note, though, that you don't generally need to initialize things to nil or zero in Go, because by default all variables (including dynamically allocated ones) are set to “zero values” according to type (numbers zero, references nil). So in your example saying new(Node) would result in a Node with both fields nil.

Solution 2 - Go

I just found out is nil

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfabrizioMView Question on Stackoverflow
Solution 1 - GoArkkuView Answer on Stackoverflow
Solution 2 - GofabrizioMView Answer on Stackoverflow