Who designed the Go programming language at Google in 2007?
Robert Griesemer, Rob Pike, and Ken Thompson
In Go, what keyword is used to launch a lightweight concurrent function (parallel process)?
go
In Go, are ++ and – operators considered expressions or statements?
Statements
(they perform side effects but produce no value and cannot be used where a value is required).
What built-in mechanism in Go is used for cleanup actions (like closing files) that should run when a function returns, in LIFO order?
defer
What is the only loop keyword in Go?
for
Go was first publicly announced and open-sourced in November 2009.
True or False
True
Go supports classes and inheritance like Java or C++.
True or False
False (It uses composition and interfaces instead; no classes/inheritance.)
In Go, the only loop keyword is for, and it can simulate while, do-while, and range-based iteration.
True or False
True
Go has a built-in ternary operator (like condition ? trueExpr : falseExpr) for concise conditional expressions.
True or False
False (No ternary operator; use if-else instead.)
Goroutines in Go are heavyweight OS threads, making massive concurrency expensive.
True or False
False (Goroutines are lightweight, cheap, multiplexed by the runtime scheduler; supports tens/hundreds of thousands.)
Will this program compile? Explain.
~~~
func main() {
x := 10
const y = 3.14
var z int = y
}
~~~
GO
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
What data structure is being implemented?
~~~
type Stack struct {
items []int
}
func (s *Stack) Push(v int) {
s.items = append(s.items, v)
}
~~~
GO
LIFO (Last In, First Out) data structure
What value of x is printed?
var x = 5
func change() {
x := 10
}
func main() {
change()
println(x)
}GO
5
What type of loop is this? How many times will “Hello” be printed and why?
for {
fmt.Println("Hello")
break
}GO
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.
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
Coroutines implemented via goroutines and channel