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.3k Golang : Implementing class(object-oriented programming style)
+17.8k Golang : Login and logout a user after password verification and redirect example
+6.8k Get Facebook friends working in same company
+19k Golang : Check whether a network interface is up on your machine
+17.4k Golang : Get future or past hours, minutes or seconds
+8.1k How to show different content from website server when AdBlock is detected?
+10.1k Golang : How to profile or log time spend on execution?
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+4.6k Adding Skype actions such as call and chat into web page examples
+8.9k Golang : Populate or initialize struct with values example
+8.1k Golang : Metaprogramming example of wrapping a function
+12.8k Golang : Convert IPv4 address to packed 32-bit binary format