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
+5.9k Linux : Disable and enable IPv4 forwarding
+23.6k Golang : Check if element exist in map
+7.6k Golang : Shuffle strings array
+6.2k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+5.7k Python : Print unicode escape characters and string
+6.6k Golang : Map within a map example
+4.9k Which content-type(MIME type) to use for JSON data
+8.4k Golang : Check if integer is power of four example
+18.5k Golang : Read binary file into memory
+18.3k Golang : Get command line arguments
+5.5k Golang : PGX CopyFrom to insert rows into Postgres database