Go Arithmetic Operators

Arithmetic operators in Go are utilized for performing essential mathematical operations. Below are the types of arithmetic operators and their description:

Tutorials dojo strip
OperatorNameDescriptionExample
+AdditionCombines two values into a single sum.x + y
-SubtractionReduces one value by another.x - y
*MultiplicationMultiplies two values together.x * y
/DivisionDivides one value by another.x / y
%ModulusReturns the remainder after division.x % y
++IncrementIncreases the value of a variable by 1.x++
--DecrementDecreases the value of a variable by 1.x--




Example Code

package main

import "fmt"

func main() {
    x := 100
    y := 50
    z := 20

    // Addition
    sum := x + y
    fmt.Println("Sum:", sum)

    // Subtraction
    difference := x - y
    fmt.Println("Difference:", difference)

    // Multiplication
    product := y * z
    fmt.Println("Product:", product)

    // Division
    quotient := x / y
    fmt.Println("Quotient:", quotient)

    // Modulus
    remainder := x % z
    fmt.Println("Remainder:", remainder)

    // Increment
    x++
    fmt.Println("Incremented x:", x)

    // Decrement
    y--
    fmt.Println("Decremented y:", y)
}

Tutorials dojo strip
Scroll to Top