basics Flashcards

(11 cards)

1
Q

Front

A

Back

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you declare a variable in Go?

A

var x int = 42

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s the short variable declaration syntax in Go?

A

x := 42

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you define a function in Go?

A

func add(a int, b int) int { return a + b }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you define a struct in Go?

A

type Person struct { Name string; Age int }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you write a for loop in Go?

A

for i := 0; i < 10; i++ { fmt.Println(i) }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you create a slice from an array in Go?

A

slice := arr[1:4]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you return multiple values from a function in Go?

A

a, b := myFunc()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you define an interface in Go?

A

type Reader interface { Read(p []byte) (n int, err error) }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you write a switch statement in Go?

A

switch x := time.Now().Weekday(); x { case time.Saturday: … }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you defer a function call in Go?

A

defer fmt.Println(“done”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly