TutorialPedia.org
Toggle Menu
Home
Online Go Compiler
Tutorials
JavaScript Tutorials
Golang Tutorials
Linux Command Line Tutorials
Blog
All Posts
Go Data Structures and Interfaces
Assess your knowledge of slices,maps,structs,and interfaces in Go.
1. What data structure in Go is a fixed-size sequence of elements?
array
slice
map
struct
2. Which operations can be performed on a slice in Go?
append
len
cap
delete
3. Maps in Go are thread-safe for concurrent writes without synchronization.
True
False
4. What function is used to check if a key exists in a map (hint: the second return value)?
5. What is the result of len(make([]int, 5, 10))?
5
10
0
error
6. Which are valid ways to create a non-nil map in Go?
make(map[string]int)
map[string]int{}
var m map[string]int
new(map[string]int)
7. An empty interface (interface{}) can hold values of any type in Go.
True
False
8. What term describes converting an interface value to a concrete type using .(T)?
9. Which data structure is typically implemented using a slice with append and len for LIFO operations?
stack
queue
tree
map
10. Which statements about structs in Go are true?
Can contain fields of different types
Must have methods to be used
Can be compared with == if all fields are comparable
Are reference types
11. A nil interface (interface{}) in Go holds both a nil type and a nil value.
True
False
12. What is the capacity of a slice created with make([]int, 0, 5) after appending 3 elements?
13. What happens when you append to a slice that has reached its capacity?
It panics
It overwrites existing elements
It creates a new underlying array with increased capacity
It returns nil
14. Which are interfaces defined in the Go standard library?
io.Reader
fmt.Stringer
math.Sqrt
sort.Interface
15. A struct can implement multiple interfaces in Go.
True
False
16. What method must a type implement to satisfy the fmt.Stringer interface?
17. Which data structure in Go uses key-value pairs for efficient lookups?
array
slice
map
struct
18. Which of the following are value types in Go?
int
slice
struct
map
19. The zero value of a slice variable in Go is nil.
True
False
20. What is returned when accessing a key that does not exist in a non-nil map (e.g., m["key"] where m is initialized but has no 'key')?
Reset
Answered 0 of 0 — 0 correct