Golang : Null and nil value
Programmers coming from different programming languages to Golang might wonder how does one deal with NULL values. I put down these reminders below about NULL value for myself and maybe this can be useful to you as well.
Here you go :
Golang does not support NULL.
Nil is the equivalent of NULL in Golang.
All variables by default are initiated with the nil(zero) value.
Example usage of nil :
correctHash := sha1.New() fmt.Printf("%x \n", correctHash.Sum(nil))
Function returning nil will NOT compile,
// not OK func getName() string { return nil }
but returning nil to a pointer or reference (such as a struct) is ok and will compile.
type Person struct { name string } // OK func getName() *Person { return nil }
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.5k Golang : Heap sort example
+17k Golang : When to use init() function?
+6.1k Golang : Detect face in uploaded photo like GPlus
+6.6k Swift : substringWithRange() function example
+11.7k Golang : Convert a rune to unicode style string \u
+16.2k Golang : Get IP addresses of a domain name
+5k Golang : Print instead of building pyramids
+7.8k Golang : Variadic function arguments sanity check example
+6.7k Golang : Pat multiplexer routing example
+12.3k Golang : Arithmetic operation with numerical slices or arrays example
+6.7k Golang : Gargish-English language translator
+13.5k Golang : How to determine if a year is leap year?