0
0
Goprogramming~20 mins

Why operators are needed in Go - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Operator Mastery in Go
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
What is the output of this Go code using operators?

Look at this Go program that uses operators to calculate a value. What will it print?

Go
package main
import "fmt"
func main() {
  a := 10
  b := 3
  c := a / b
  fmt.Println(c)
}
ACompilation error
B3.3333333333333335
C4
D3
Attempts:
2 left
๐Ÿ’ก Hint

Remember that dividing two integers in Go results in an integer.

๐Ÿง  Conceptual
intermediate
1:30remaining
Why do we need operators in programming?

Which of these best explains why operators are needed in programming?

ATo create user interfaces automatically
BTo store data permanently on disk
CTo perform calculations and manipulate data easily
DTo connect to the internet
Attempts:
2 left
๐Ÿ’ก Hint

Think about what operators do with numbers and variables.

โ“ Predict Output
advanced
2:00remaining
What is the output of this Go code using bitwise operators?

Examine this Go program that uses bitwise operators. What will it print?

Go
package main
import "fmt"
func main() {
  x := 5  // binary 0101
  y := 3  // binary 0011
  z := x & y
  fmt.Println(z)
}
A1
B7
C0
D8
Attempts:
2 left
๐Ÿ’ก Hint

Bitwise AND compares each bit of two numbers.

๐Ÿ”ง Debug
advanced
2:00remaining
What error does this Go code cause and why?

Look at this Go code snippet. What error will it cause when compiled?

Go
package main
func main() {
  var a int = 5
  var b float64 = 2.0
  c := a + b
}
ACannot use a (type int) + b (type float64) without conversion
BSyntax error: missing semicolon
CRuntime panic: invalid operation
DNo error, prints 7
Attempts:
2 left
๐Ÿ’ก Hint

Check if Go allows adding int and float64 directly.

๐Ÿš€ Application
expert
2:30remaining
How many items are in the resulting map after this Go code runs?

This Go code uses operators to fill a map. How many key-value pairs does the map contain after running?

Go
package main
import "fmt"
func main() {
  m := make(map[int]int)
  for i := 0; i < 5; i++ {
    if i%2 == 0 {
      m[i] = i * 2
    }
  }
  fmt.Println(len(m))
}
A5
B3
C2
D0
Attempts:
2 left
๐Ÿ’ก Hint

Count how many numbers from 0 to 4 are even.