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
+7.9k Golang : Intercept and compare HTTP response code example
+9.5k Swift : Convert (cast) String to Integer
+7k Swift : Convert (cast) String to Float
+5.1k Javascript : Get operating system and browser information
+8.3k Golang : Changing a RGBA image number of channels with OpenCV
+4.4k Unix/Linux : How to archive and compress entire directory ?
+35k Golang : Display float in 2 decimal points and rounding up or down
+4.7k Fix yum-complete-transaction error
+6.2k Golang : Of hash table and hash map
+9.9k Golang : Intercept and process UNIX signals example
+4k Fix Google Analytics Redundant Hostnames problem