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
+12.9k Golang : How to calculate the distance between two coordinates using Haversine formula
+10.6k Golang : Get UDP client IP address and differentiate clients by port number
+12.7k Golang : Convert IPv4 address to packed 32-bit binary format
+11.2k Golang : Characters limiter example
+13.2k Golang : Generate Code128 barcode
+12.1k Golang : 2 dimensional array example
+11.8k Golang : Clean formatting/indenting or pretty print JSON result
+37.2k Upload multiple files with Go
+7.2k Android Studio : How to detect camera, activate and capture example
+6.6k Golang : Find the longest line of text example
+19k Golang : Execute shell command
+6.8k Golang : Levenshtein distance example