Operator and syntax

Go arithmetic operators

Numeric arithmetic requires compatible operand types; + also concatenates strings. Integer division truncates toward zero and remainder has the dividend sign. Integer division by zero panics at runtime; constant division by zero is invalid. Example output: '-4 -10 -21 -2 -1'.

Formal Syntax & Structure

go syntaxgo
+ - * / %

Working Example

Example Snippetgo
package main
import (  "fmt")
func main() {  a, b := -7, 3  fmt.Println(a+b, a-b, a*b, a/b, a%b)}
Go Reference