Go code
total := 6 + 2
fmt.Println(total)Line-by-line explanation
- The short declaration creates total.
- The plus operator adds 6 and 2.
- Println displays the result.
Expected output
8This is the expected result.
Go uses - for subtraction, * for multiplication, / for division, and % for the remainder. Integer division discards the fractional part.
Go code
answer := 7 / 2
fmt.Println(answer)Line-by-line explanation
- Both values are integers.
- Integer division produces 3, not 3.5.
- The result is displayed.
Expected output
3This is the expected result.