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.6k Android Studio : Indicate progression with ProgressBar example
+9.9k Golang : Read until certain character to break for loop
+37.8k Golang : How to iterate over a []string(array)
+14.1k Golang : How to login and logout with JWT example
+18.5k Golang : How to count the number of repeated characters in a string?
+44.1k Golang : Read tab delimited file with encoding/csv package
+15k Golang :Trim white spaces from a string
+8.4k Golang : How to protect your source code from client, hosting company or hacker?
+17.3k Golang : Get path name to current directory or folder
+8.1k Golang : Timeout example
+15.4k Golang : Gzip file example
+27.9k Golang : missing Git command