simple golang questions All resources https://twitter.com/bot_golang
package main
import "fmt"
func hello(a...interface{}){
fmt.Println(len(a))
}
func main() {
hello(nil)
}
answer options
- 1
- runtime panic
- compilation error
click show answer
- 1
package main
import "fmt"
func hello(p ...int){
if p==nil {
fmt.Println("nil")
return
}
fmt.Println("not nil")
}
func main() {
hello()
}
answer options
- nil
- not nil
- compilation error
click show answer
- nil
package main
import "fmt"
func main() {
i := 0
_,i = 5,8
fmt.Println(i)
}
answer options
- runtime panic
- 8
- compilation error
- 5
click show answer
- 8
package main
import "fmt"
func main() {
s := make(map[string]int)
delete(s,"h")
fmt.Println(s["h"])
}
answer options
- runtime panic
- 0
- compilation error
click show answer
- 0
package main
import "fmt"
func main() {
fmt.Printf("%%")
}
answer options
- 0.0
- compilation error
- %
- %%
click show answer
- %
package main
import "fmt"
func hello(i int) {
fmt.Println(i)
}
func main() {
i := 5
defer hello(i)
i = i + 10
}
answer options
- 5
- 15
- 0
click show answer
- 5
package main
import "fmt"
func main() {
var i interface{}
if i == nil {
fmt.Println("nil")
return
}
fmt.Println("not nil")
}
click show answer
- nil
package main
import "fmt"
func main() {
a := 5
b := 8.1
fmt.Println(a+b)
}
answer options
- 13.1
- 13
- compilation error
click show answer
- compilation error