Created
August 21, 2020 20:54
-
-
Save pedrobertao/09bab1f37dd411d3af687fcedc6556ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type Person struct { | |
Name string | |
Surname string | |
} | |
func main() { | |
var joe Person | |
var maria *Person | |
var john = Person{ | |
Name: "John", | |
Surname: "Smith", | |
} | |
if (joe == Person{}) { | |
fmt.Printf("Yes, it is empty: %v \n", joe) | |
} | |
/* | |
Output: Yes, it is empty: { } | |
*/ | |
if maria == nil { | |
fmt.Printf("Yes, it is empty: %v \n", maria) | |
} | |
/* | |
Output: Yes, it is empty: <nil> | |
*/ | |
if (john != Person{}) { | |
fmt.Printf("Not, it is not empty: %v \n", john) | |
} | |
/* | |
Output: Not, it is not empty: {John Smith} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment