0
0
Goprogramming~20 mins

Assignment operators in Go - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Assignment Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of compound assignment with addition
What is the output of this Go program?
Go
package main
import "fmt"
func main() {
    x := 10
    x += 5
    fmt.Println(x)
}
ACompilation error
B10
C5
D15
Attempts:
2 left
๐Ÿ’ก Hint
The += operator adds the right value to the left variable.
โ“ Predict Output
intermediate
2:00remaining
Output of compound assignment with bitwise AND
What is the output of this Go program?
Go
package main
import "fmt"
func main() {
    a := 12  // binary 1100
    a &= 5  // binary 0101
    fmt.Println(a)
}
A4
B5
C12
D8
Attempts:
2 left
๐Ÿ’ก Hint
Bitwise AND keeps bits set in both numbers.
โ“ Predict Output
advanced
2:00remaining
Value after multiple compound assignments
What is the value of variable x after running this Go code?
Go
package main
import "fmt"
func main() {
    x := 3
    x *= 4
    x -= 5
    x /= 2
    fmt.Println(x)
}
A3
B1
C4
D2
Attempts:
2 left
๐Ÿ’ก Hint
Apply each operation step by step.
โ“ Predict Output
advanced
2:00remaining
Output of compound assignment with string concatenation
What is the output of this Go program?
Go
package main
import "fmt"
func main() {
    s := "Go"
    s += "lang"
    fmt.Println(s)
}
ACompilation error
BGolang
CGo+lang
DGo lang
Attempts:
2 left
๐Ÿ’ก Hint
The += operator concatenates strings in Go.
โ“ Predict Output
expert
2:00remaining
Output of compound assignment with float division and type conversion
What is the output of this Go program?
Go
package main
import "fmt"
func main() {
    var x float64 = 10.0
    var y int = 4
    x /= float64(y)
    fmt.Printf("%.2f", x)
}
A2
B2.5
C2.50
DCompilation error
Attempts:
2 left
๐Ÿ’ก Hint
Remember to convert int to float64 before division.