0
0
Goprogramming~5 mins

Arithmetic operators in Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are arithmetic operators in Go?
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/
What is the result of 10 % 4 in Go?
A2
B0
C4
D6
What type should variables be to get a decimal result when dividing in Go?
Abool
Bstring
Cint
Dfloat32 or float64
What happens if you divide an integer by zero in Go?
AReturns zero
BReturns infinity
CCauses a runtime error (panic)
DReturns NaN
Which operator subtracts one number from another in Go?
A-
B*
C+
D/
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.