What is the output of the following code?
package main
import "fmt"
func main() {
x := []int{1, 2, 3}
y := x[:2]
y[0] = 4
fmt.Println(x[0])
}
What is the output of the following code?
package main
import "fmt"
func main() {
x := 1
addOne(&x)
fmt.Println(x)
}
func addOne(y *int) {
*y = *y + 1
}
What is the output of the following code?
package main
import "fmt"
func main() {
ch := make(chan int)
go func() {
ch <- 1
}()
fmt.Println(<-ch)
}
What is an interface in Go?
What is the output of the following code?
go
Copy code
package main
import "fmt"
func main() {
var x *int
fmt.Println(*x)
}
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)
}
Which of the following is not a valid way to declare an interface in Go?
What is the output of the following code?
package main
import (
"fmt"
)
func add(numbers ...int) int {
sum := 0
for _, n := range numbers {
sum += n
}
return sum
}
func main() {
nums := []int{1, 2, 3, 4}
fmt.Println(add(nums...))
}
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
}
What is the output of the following code?
package main
import (
"fmt"
"time"
)
func main() {
done := make(chan bool)
go func() {
time.Sleep(1 * time.Second)
done <- true
}()
fmt.Println("Waiting...")
<-done
fmt.Println("Done")
}