Comparing Structs with the Different Values Assigned to Data Fields
Structs of the same type can be compared using comparison operator.
Example
package main
import "fmt"
type rectangle struct {
length float64
breadth float64
color string
}
func main() {
var rect1 = rectangle{10, 20, "Green"}
rect2 := rectangle{length: 20, breadth: 10, color: "Red"}
if rect1 == rect2 {
fmt.Println("True")
} else {
fmt.Println("False")
}
rect3 := new(rectangle)
var rect4 = &rectangle{}
if rect3 == rect4 {
fmt.Println("True")
} else {
fmt.Println("False")
}
}
Most Helpful This Week
How to Convert string to integer type in Go?
How do you handle HTTP server health checks in Go?
How to set timeout for http.Get() requests in Golang?
Find out how many logical processors used by current process
How to concatenate two or more slices in Golang?
Golang program for implementation of Linked List