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
+33.1k Golang : How to check if a date is within certain range?
+13.7k Golang : Query string with space symbol %20 in between
+25.6k Golang : Generate MD5 checksum of a file
+10.5k Golang : cannot assign type int to value (type uint8) in range error
+8.3k Golang : Routes multiplexer routing example with regular expression control
+11.9k Golang : GTK Input dialog box examples
+13.5k Golang : Read from buffered reader until specific number of bytes
+14.6k Golang : Execute function at intervals or after some delay
+17.8k Golang : Read data from config file and assign to variables
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+18.5k Golang : Write file with io.WriteString
+9.8k Golang : Format strings to SEO friendly URL example