Remainder Operator in Go

Go Remainder Operator takes two operands and returns the remainder when first operand is divided by second operand.

Go Remainder Operator applies to integers only.

In this tutorial, we will learn about the syntax of Remainder Operator, and some example scenarios on how to use Remainder operator.

Syntax

The syntax to get remainder of the division a/b, using Remainder Operator is

</>
Copy
a%b

where a and b are operands and % is the operator symbol.

Return Value

The operator returns an integer value.

Example

In the following example, we take two integer values in a and b, and find the remainder when a is divided by b.

Example.go

</>
Copy
package main

func main() {
	a := 8
	b := 3
	result := a % b
	println("Remainder of a/b = ", result)
}

Output

Remainder of a/b =  2

Conclusion

In this Go Tutorial, we learned about Division Operator in Go language, with the syntax and example programs.