package main import "fmt" func main() { a := 5 b := 10 c := 15 fmt.Println(a < b && b < c) fmt.Println(a > b || b < c) fmt.Println(!(a == 5)) }
The first line checks if 5 is less than 10 AND 10 is less than 15, both true, so true.
The second line checks if 5 is greater than 10 OR 10 is less than 15, second is true, so true.
The third line negates if 5 equals 5, which is true, so negation is false.
package main import "fmt" func main() { s1 := "apple" s2 := "banana" fmt.Println(s1 < s2) fmt.Println(s1 == s2) fmt.Println(s1 > s2) }
"apple" is lexicographically less than "banana", so first is true.
They are not equal, so second is false.
"apple" is not greater than "banana", so third is false.
package main import "fmt" func main() { var x int = 10 var y float64 = 10.0 fmt.Println(x == y) }
Go does not allow direct comparison between int and float64 types, causing a compilation error.
package main import "fmt" func main() { type Point struct { x, y int } p1 := Point{1, 2} p2 := Point{1, 2} fmt.Println(p1 == p2) fmt.Println(p1 != p2) }
Both p1 and p2 have the same values, so p1 == p2 is true and p1 != p2 is false.
package main import "fmt" func main() { var p *int = nil var i interface{} = p fmt.Println(i == nil) fmt.Println(p == nil) }
The interface i holds a nil value but is not itself nil, so i == nil is false.
The pointer p is nil, so p == nil is true.
