Arithmetic operators in Golang

Arithmetic operators are mathematical operators that are used to perform basic arithmetic operations on operands in Golang. Golang supports the following arithmetic operators:

Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
Remainder (%)

Here are some examples of using arithmetic operators in Golang:

package main

import “fmt”

func main() {
var a = 10
var b = 20

fmt.Println(“a + b =”, a+b)
fmt.Println(“a – b =”, a-b)
fmt.Println(“a * b =”, a*b)
fmt.Println(“b / a =”, b/a)
fmt.Println(“b % a =”, b%a)
}

The output of this program will be:

a + b = 30
a – b = -10
a * b = 200
b / a = 2
b % a = 0

Practice Questions on Arithmetic Operators in Golang

Here are some practice questions on arithmetic operators in Golang:

What is the arithmetic operator used for addition in Golang?

A. +
B. –
C. *
D. /

Answer: A

What is the arithmetic operator used for subtraction in Golang?

A. +
B. –
C. *
D. /

Answer: B

What is the output of the following Go code?

package main

import “fmt”

func main() {
var a = 5
var b = 2

fmt.Println(“a * b =”, a*b)
fmt.Println(“a / b =”, a/b)
fmt.Println(“a % b =”, a%b)
}

A. a * b = 10, a / b = 2, a % b = 1
B. a * b = 10, a / b = 2, a % b = 0
C. a * b = 7, a / b = 2, a % b = 1
D. a * b = 7, a / b = 2, a % b = 0

Answer: A

What is the arithmetic operator used for multiplication in Golang?

A. +
B. –
C. *
D. /

Answer: C

What is the output of the following Go code?

package main

import “fmt”

func main() {
var a = 8
var b = 3

fmt.Println(“a + b =”, a+b)
fmt.Println(“a – b =”, a-b)
fmt.Println(“a * b =”, a*b)
fmt.Println(“a / b =”, a/b)
fmt.Println(“a % b =”, a%b)
}

A. a + b = 11, a – b = 5, a * b = 24, a / b = 2, a % b = 2
B. a + b = 11, a – b = 5, a * b = 24, a / b = 2, a % b = 1
C. a + b = 12, a – b = 5, a * b = 24, a / b = 2, a % b = 2
D. a + b = 12, a – b = 5, a * b = 24, a / b = 2, a % b = 1

Answer: B

Get industry recognized certification – Contact us

Menu