package main
const X = '\x61' // 'a'
const Y = 0x62
const A = Y - X // 1
const B int64 = 1
var n = 32
func main() {
if A == B {
println(A << n >> n, B << n >> n)
}
}
Choices:
Answer: 0 1
Run it on Go play.
Key points:
X
is a rune constant (in other words, its default type is rune
, a.k.a int32
, a 32-bit integer type).
Untyped Y
is an int constant (in other words, its default type is int
, a 64-bit integer type on 64-bit OSes).
A << n
overflows, so it is evaluated as 0;
on the other hand, the expression B << n
doesn't overflow.