Recall & Review
beginner
What is the purpose of assignment operators in Go?
Assignment operators in Go are used to assign values to variables. They can also combine an operation with assignment, like adding a value and then assigning the result.
Click to reveal answer
beginner
What does the operator += do in Go?
The operator += adds the right-hand value to the left-hand variable and then assigns the result back to that variable. For example, x += 3 means x = x + 3.
Click to reveal answer
beginner
Explain the difference between = and *= in Go.
The = operator assigns a value directly to a variable. The *= operator multiplies the variable by a value and assigns the result back to the variable. For example, x *= 2 means x = x * 2.
Click to reveal answer
intermediate
Can you use assignment operators with all data types in Go?
Assignment operators work with numeric types like int, float, and also with strings for the = operator. Operators like += work with numbers and strings (for concatenation). They do not work with all types, like structs or arrays directly.
Click to reveal answer
beginner
What happens if you write x -= 5 in Go?
The value 5 is subtracted from the current value of x, and the result is stored back in x. It is the same as writing x = x - 5.
Click to reveal answer
What does the operator /= do in Go?
✗ Incorrect
The /= operator divides the variable by the right-hand value and assigns the result back to the variable.
Which operator would you use to add 10 to a variable x in Go?
✗ Incorrect
The += operator adds the right-hand value to the variable and assigns the result back.
What is the result of this code snippet?
var x = 5
x *= 3
✗ Incorrect
The *= operator multiplies x by 3, so x becomes 15.
Which assignment operator can be used to concatenate strings in Go?
✗ Incorrect
The += operator can concatenate strings by adding the right string to the left.
Is this statement true or false? "The = operator can be used to assign a value to a variable."
✗ Incorrect
The = operator assigns any compatible value to a variable.
Explain how assignment operators like += and *= work in Go with an example.
Think about how you can shorten x = x + 3 using an assignment operator.
You got /3 concepts.
List common assignment operators in Go and describe what each does.
Start with simple ones like = and +=, then mention others that combine operations with assignment.
You got /11 concepts.