GO LANG Flashcards

(15 cards)

1
Q

Who designed the Go programming language at Google in 2007?

A

Robert Griesemer, Rob Pike, and Ken Thompson

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

In Go, what keyword is used to launch a lightweight concurrent function (parallel process)?

A

go

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

In Go, are ++ and – operators considered expressions or statements?

A

Statements
(they perform side effects but produce no value and cannot be used where a value is required).

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

What built-in mechanism in Go is used for cleanup actions (like closing files) that should run when a function returns, in LIFO order?

A

defer

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

What is the only loop keyword in Go?

A

for

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

Go was first publicly announced and open-sourced in November 2009.
True or False

A

True

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

Go supports classes and inheritance like Java or C++.
True or False

A

False (It uses composition and interfaces instead; no classes/inheritance.)

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

In Go, the only loop keyword is for, and it can simulate while, do-while, and range-based iteration.
True or False

A

True

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

Go has a built-in ternary operator (like condition ? trueExpr : falseExpr) for concise conditional expressions.
True or False

A

False (No ternary operator; use if-else instead.)

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

Goroutines in Go are heavyweight OS threads, making massive concurrency expensive.
True or False

A

False (Goroutines are lightweight, cheap, multiplexed by the runtime scheduler; supports tens/hundreds of thousands.)

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

Will this program compile? Explain.
~~~
func main() {
x := 10
const y = 3.14
var z int = y
}
~~~

GO

A

No, the program will not compile. Even though y is an untyped constant, 3.14 is not representable as an int without an explicit conversion. Go enforces strong static typing

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

What data structure is being implemented?
~~~
type Stack struct {
items []int
}
func (s *Stack) Push(v int) {
s.items = append(s.items, v)
}
~~~

GO

A

LIFO (Last In, First Out) data structure

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

What value of x is printed?

var x = 5
func change() {
       x := 10
}
func main() {
       change()
       println(x)
}

GO

A

5

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

What type of loop is this? How many times will “Hello” be printed and why?

for {
       fmt.Println("Hello")
       break
}

GO

A

Infinite loop (for without condition). “Hello” will be printed once. Even if the loop has no condition, the break statement immediately exits the loop after the first iteration.

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

What control-level structure does this program demonstrate?

func send(ch chan int) {
       ch <- 5
}
func main() {
       ch := make(chan int)
       go send(ch)
       fmt.Println(<-ch)
}

GO

A

Coroutines implemented via goroutines and channel

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