WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Go - Arithmetic Operators


The following table lists the arithmetic operators for all Go languages. Suppose the A value is 10 and the B value is 20.

OperatorsDescriptionInstances
+Addition A + B Output 30
-subtraction A - B output result -10
*Multiplication A * B Output Results 200
/Division B / A Output 2
%Residual B % A Output 0
++Increase A++ Output 11
--Decrement A-- Output 9

The following example demonstrates the use of individual arithmetic operators:

example

package main

import "fmt"

func main() {

   var a int = 21
   var b int = 10
   var c int

   c = a + b
   fmt.Printf("first row - c Value %d\n", c )
   c = a - b
   fmt.Printf("second line - c Value %d\n", c )
   c = a * b
   fmt.Printf("The third row - c Value %d\n", c )
   c = a / b
   fmt.Printf("Fourth line - c Value %d\n", c )
   c = a % b
   fmt.Printf("The fifth line - c Value %d\n", c )
   a++
   fmt.Printf("Sixth line - a Value %d\n", a )
   a=21   // For the convenience of testingļ¼Œa Reassigned here 21
   a--
   fmt.Printf("The seventh line - a Value %d\n", a )
}

The above example results:

First line - c The value is  31
Second line - c values 11
third line - c values 210
fourth line - c values 2
Fifth line - c The value is  1
The sixth line - a values 22
The seventh line - a values 20