Arithmetic operators are symbols used to perform basic math operations like addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
Click to reveal answer
beginner
What does the % operator do in Go?
The % operator gives the remainder after dividing two integers. For example, 7 % 3 equals 1 because 7 divided by 3 leaves a remainder of 1.
Click to reveal answer
intermediate
How do you perform division with floating-point numbers in Go?
To divide floating-point numbers, use variables of type float32 or float64. For example, 5.0 / 2.0 equals 2.5.
Click to reveal answer
intermediate
What happens if you divide by zero in Go?
Dividing by zero causes a runtime panic in Go. You should always check the divisor before dividing to avoid this error.
Click to reveal answer
beginner
Write a Go expression to add two variables a and b.
The expression is: a + b
Click to reveal answer
Which operator is used for multiplication in Go?
A-
B*
C+
D/
✗ Incorrect
The * symbol is used for multiplication.
What is the result of 10 % 4 in Go?
A2
B0
C4
D6
✗ Incorrect
10 divided by 4 leaves a remainder of 2, so 10 % 4 equals 2.
What type should variables be to get a decimal result when dividing in Go?
Abool
Bstring
Cint
Dfloat32 or float64
✗ Incorrect
Only float32 or float64 types can hold decimal numbers for division results.
What happens if you divide an integer by zero in Go?
AReturns zero
BReturns infinity
CCauses a runtime error (panic)
DReturns NaN
✗ Incorrect
Dividing by zero causes a runtime panic error in Go.
Which operator subtracts one number from another in Go?
A-
B*
C+
D/
✗ Incorrect
The - operator subtracts numbers.
Explain the use of arithmetic operators in Go with examples.
Think about how you do basic math with numbers in Go code.
You got /6 concepts.
What precautions should you take when using division in Go?
Consider what happens if the divisor is zero or if you want decimal results.
You got /3 concepts.
Practice
(1/5)
1. Which arithmetic operator in Go is used to find the remainder of a division?
easy
A. /
B. +
C. *
D. %
Solution
Step 1: Understand the remainder operation
The remainder operator returns what is left after division.
Step 2: Identify the correct operator in Go
In Go, the remainder operator is represented by the percent sign '%'.
Final Answer:
% -> Option D
Quick Check:
Remainder = % [OK]
Hint: Remainder uses % like in many languages [OK]
Common Mistakes:
Confusing division / with remainder %
Using * for remainder
Using + for remainder
2. Which of the following is the correct way to write a multiplication operation in Go?
easy
A. a x b
B. a . b
C. a * b
D. a & b
Solution
Step 1: Recall Go's multiplication syntax
Go uses the asterisk '*' symbol for multiplication.
Step 2: Check each option
Only 'a * b' uses the correct multiplication operator.
Final Answer:
a * b -> Option C
Quick Check:
Multiplication = * [OK]
Hint: Use * for multiplication, not x or & [OK]
Common Mistakes:
Using 'x' instead of '*'
Using '.' or '&' for multiplication
Confusing syntax with other languages
3. What is the output of this Go code?
package main
import "fmt"
func main() {
a := 7
b := 3
fmt.Println(a / b)
}
medium
A. 2.3333333
B. 2
C. 3
D. 0
Solution
Step 1: Identify variable types and operation
Both a and b are integers, so division is integer division.
Step 2: Calculate integer division result
7 divided by 3 is 2.333..., but integer division drops decimals, so result is 2.
Final Answer:
2 -> Option B
Quick Check:
Integer division 7/3 = 2 [OK]
Hint: Integer division drops decimals, result is int [OK]
Common Mistakes:
Expecting float result
Confusing integer division with float division
Using wrong operator
4. Find the error in this Go code snippet:
package main
import "fmt"
func main() {
x := 10
y := 0
fmt.Println(x / y)
}
medium
A. Division by zero causes runtime panic
B. Syntax error: missing semicolon
C. Variable y is not declared
D. No error, prints 0
Solution
Step 1: Analyze the division operation
The code divides x by y, where y is zero.
Step 2: Understand Go's behavior on division by zero
Dividing by zero causes a runtime panic (error) in Go.
Final Answer:
Division by zero causes runtime panic -> Option A
Quick Check:
Division by zero = runtime panic [OK]
Hint: Never divide by zero; it crashes the program [OK]
Common Mistakes:
Thinking it prints 0
Expecting compile-time error
Ignoring runtime panic
5. Given the Go code below, what is the output?
package main
import "fmt"
func main() {
a := 15
b := 4
c := a % b
d := a / b
fmt.Println(c + d)
}
hard
A. 6
B. 3
C. 19
D. 4
Solution
Step 1: Calculate remainder c = a % b
15 % 4 equals 3 because 4*3=12 and 15-12=3.
Step 2: Calculate integer division d = a / b
15 / 4 equals 3 because integer division drops decimals.
Step 3: Add c + d
3 + 3 equals 6.
Final Answer:
6 -> Option A
Quick Check:
15 % 4 = 3, 15 / 4 = 3, 3 + 3 = 6 [OK]
Hint: Add remainder and integer division results carefully [OK]
Common Mistakes:
Miscomputing remainder
Using float division instead of integer
Adding wrong values
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.