I am a newbie to golang, actually, I am new to type based programming. I have only knowledge of JS.
While going through simple examples in golang tutorials. I found that adding a1 + a2 provides a negative integer value?
var a1 int16 = 127
var a2 int16 = 32767
var rr int16 = a1 + a2
fmt.Println(rr)
Result:
-32642
Excepted:
- The compiler will throw an error as a exceeded the int16 max.
- ( OR ) GO automatically convert the int16 to int32.
- 32,894
Can you guys explain why it is showing -32642.