Look at this Go program that uses operators to calculate a value. What will it print?
package main import "fmt" func main() { a := 10 b := 3 c := a / b fmt.Println(c) }
Remember that dividing two integers in Go results in an integer.
In Go, dividing two integers uses integer division, so 10 / 3 equals 3, not 3.33.
Which of these best explains why operators are needed in programming?
Think about what operators do with numbers and variables.
Operators let us do math and change data values, which is essential for programming logic.
Examine this Go program that uses bitwise operators. What will it print?
package main import "fmt" func main() { x := 5 // binary 0101 y := 3 // binary 0011 z := x & y fmt.Println(z) }
Bitwise AND compares each bit of two numbers.
5 in binary is 0101, 3 is 0011. ANDing them gives 0001 which is 1.
Look at this Go code snippet. What error will it cause when compiled?
package main func main() { var a int = 5 var b float64 = 2.0 c := a + b }
Check if Go allows adding int and float64 directly.
Go does not allow adding int and float64 without explicit conversion.
This Go code uses operators to fill a map. How many key-value pairs does the map contain after running?
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)) }
Count how many numbers from 0 to 4 are even.
Only 0, 2, and 4 are even, so the map has 3 entries.