Golang quiz
s := "hello"
result := len(s)
Select the "result" value:
1
5
10
20
package main
import “fmt”
func main() {
var a int8 = 3
var b int16 = 4
sum := a + b
fmt.Println(sum)
}
7
4
3
Invalid operation: a + b (mismatched types int8 and int16)
Does Go support optional parameters in functions?
Yes
No
On what data types you can use "for - range" statement?
Array, slice, map
Array, slice, map, string
Slice, map, string
Slice, map
package main
import “fmt”
func main() {
for I := 0; I < 4; i++ {
defer fmt.Print(i)
}
}
0123
3210
0000
3333
When will init() function be called?
A) Before main() function in main package
B) After importing a package with defined init() function
C) Only when you call it
A and b
Is it possible to declare multiple types of variables in single declaration in Go?
var a, b, c = 3, 4, “foo”
Yes
No
What’s the output of the following code?
package main
import "fmt"
const (
a = iota
b = iota
c = iota
)
const (
d, e, f = iota, iota, iota
)
func main() {
fmt.Println(a, b, c, d, e, f)
}
0 1 2 3 4 5
0 1 2 0 1 2
0 1 2 0 0 0
0 0 0 0 1 2
s := "привет"
result := len(s)
Select the "result" value:
1
6
12
24
What's the default buffer size of the channel in Go?
0
1
No default size
What are the default values of these types: string,`*string` ?
"", nil
"", ""
Nil, nil
Nil, ""
Can short declaration ":=" be used for defining global variables?
Yes
No
Arrays are value types. In case of arrays perform as arguments, functions get their copies instead of a reference. Don’t they?
Yes
No
Which one of the following is correct?
A. const Pi = math.Pi
B. const Pi = 3.14
C. Both a and b are correct
D. None of the above
Which of the following variables are exportable from another external package?
package main var ( aName string BigBro string 爱 string ) func main()
AName, BigBro
BigBro
AName, BigBro, 爱
BigBro, 爱
What's the sequence for the output of the following code?
package main import ( "fmt" "sync" ) func main() { var wg sync.WaitGroup wg.Add(1) go func() { fmt.Println("1") wg.Done() }() wg.Add(1) go func() { fmt.Println("2") wg.Done() }() wg.Wait() fmt.Println("3") }
Always 1 2 3
Always 2 1 3
3
"1 2 3" or "2 1 3"
package main import "fmt" func main() { a := make([]int, 3, 4) a[0], a[1], a[2] = 0, 1, 2 b := append(a, 66) b[0] = 6 c := append(a, 77) c[0] = 7 d := append(a, 88, 99) d[0] = 9 //fmt.Println(a) fmt.Println(b) //fmt.Println(c) //fmt.Println(d) }Print b result?
6 1 2 66
7 1 2
7 1 2 77
9 1 2 88 99
Does this compile? Do you get a runtime panic? Do you get a value printed?
package main import "fmt" func main() { m := map[string]int{"one": 1, "two": 2, "three": 3} fmt.Println(m["four"]) }
Nil
0
Panic
Compile error
package main
func main() {
one := 0
one := 1
}
value of one?
0
1
Compile error
Nil
package main
import "fmt"
func main() {
x := 1
{
x := 2
}
fmt.Println(x)
}
print result?
1
2
Compile error
0
package main
import "fmt"
func main() {
x := "text"
x[0] = 'T'
fmt.Println(x)
}
print result?
Compile error
Text
Text
Panic
package main
import "fmt"
func main() {
x := "text"
fmt.Println(x[0])
}
print result?
Text
Compile error
T
116
third := []string{"a", "b", "c", "d", "e", "f"}
for a, b := range third {
fmt.Println(a, b)
break
}
print result?
A a
A b
0 a
1 a
package main import "fmt" var stuff = "not ready" func init() { stuff = "ready" } func main() { fmt.Println("The stuff is", stuff) }
print result?
The stuff is stuff
The stuff is ready
The stuff is not ready
Compile error
func sum(args ...int) {
...
}
the args is type :
Int
[]interface{}
[]int
Interface{}
var a = [...]int {0,1,2,3,4,5,6,7}
var s = make([]int, 6)
n1 := copy(s, a[0:])
n2 := copy(s, s[2:])
value of s ?
0, 1, 2, 3, 4, 5
0, 1, 2, 3, 4, 5, 6, 7
2,3,4,5
2, 3, 4, 5, 4, 5
package main
import "fmt"
type User struct {
name string
age int
}
func (u *User) Greeting() { fmt.Println("Hello I am user") }
type Admin struct {
User
Level int
}
func (a *Admin) Greeting() { fmt.Println("Hello I am superuser") }
func main() { a := Admin{} a.Greeting() }
print result?
Hello I am user
Hello I am superuser
Compile error
Panic
package main import "fmt" func main() { var I interface{} = "hello" f = I.(float64) fmt.Println(f) }
print result?
Compile error
Hello
342
Panic
{"name":"Golang quiz", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"s := \"привет\" result := len(s) Select the \"result\" value, s := \"hello\" result := len(s)","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
More Quizzes
210
Which Timesplitters Character Are You?
840
American Republic Study Quiz
26130
Kahoot quiz
520
French evolution
210
Confines
100
Is this a computer?
1165776
Do you have any recommendations in new papers today?
100
Language, Culture, and Power
520
Do you rlly know reee 1.2
1587
Which Fast and Furious character are you?
15815
Saulėlydis
630