What will the following code output?
package main
import "fmt"
func main() {
x := 5
y := 2
fmt.Println(x / y)
}
What will the following code output?
package main
import "fmt"
func main() {
var a [3]int
a[0] = 1
a[1] = 2
a[2] = 3
fmt.Println(a[1])
}
What is the output of the following code?
package main
import "fmt"
func main() {
var x = 5
defer func() {
fmt.Println(x)
}()
x = 10
}
What is the output of the following code?
package main
import "fmt"
func main() {
s := make([]int, 0, 5)
s = append(s, 1, 2, 3, 4)
fmt.Println(len(s))
}
What is the output of the following code?
package main
import "fmt"
func main() {
x := []int{1, 2, 3, 4}
y := x[:2]
y = append(y, 5)
fmt.Println(len(x))
}
What is the output of the following code?
package main
import "fmt"
func main() {
x := []int{1, 2, 3, 4}
y := make([]int, len(x))
copy(y, x)
fmt.Println(y[2])
}
What is the output of the following code?
package main
import "fmt"
type Employee struct {
ID int
}
func main() {
e := Employee{ID: 1}
f := &e
f.ID = 2
fmt.Println(e.ID)
}
What will the following code output?
package main
import "fmt"
func main() {
var s []int = []int{1, 2, 3}
s[1] = 4
fmt.Println(s)
}
What is the output of the following code?
package main
import "fmt"
func main() {
var x interface{} = "hello"
s := x.(string)
fmt.Println(s)
}
What is the output of the following code?
package main
import "fmt"
type Employee struct {
ID int
}
func main() {
e := Employee{ID: 1}
fmt.Println(e)
changeID(e)
fmt.Println(e)
}
func changeID(e Employee) {
e.ID = 2
}