0% found this document useful (0 votes)
14 views2 pages

Golang Questions

The program will print '222' due to all map entries pointing to the same variable 'i'. The output of the second code will be 'f3-begin', 'f2-begin', and then a panic occurs, preventing 'f1-end' and 'f2-end' from executing. A sync.WaitGroup is used to wait for a collection of goroutines to finish executing before proceeding, ensuring proper synchronization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Golang Questions

The program will print '222' due to all map entries pointing to the same variable 'i'. The output of the second code will be 'f3-begin', 'f2-begin', and then a panic occurs, preventing 'f1-end' and 'f2-end' from executing. A sync.WaitGroup is used to wait for a collection of goroutines to finish executing before proceeding, ensuring proper synchronization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1. What will be the final result of this following program?

package main

const N = 3

func main ()
m := make(map(int)*int)
for i := 0; i < N; i++ {
m[i] = &i
}
for _, v := range m {
print (*v)
}
}

2. What is the output of the following code:

package main

func f1 () {
defer printIn(“f1-begin”)
f2 ()
defer printIn(“f1-end”)
}

func f2 () {
defer printIn(“f2-begin”)
f3 ()
defer printIn(“f2-end”)
}

func f3 () {
defer printIn(“f3-begin”)
panic (0)
defer printIn(“f3-end”)
}
func main () {
f1 ()
}

3. Briefly explain the purpose of sync.WaitGroup

4. In the following code there are 2 lines of code that will cause syntax errors. Give your answer as
indicated by D, C, B, A?
package main

type AStructure struct {


}

func f(x interface {}) {


}

func g(x*interface {}) {


}

func main () {
s := AStructure{}
pointer := &s
f(s) //D
g(s) //C
f(pointer) //B
g(pointer) //A
}

5. What are the differences between an array and a slide?

6. Can a GOTO in function A jump to a label inside function B in Golang?

7. What is the advantage and disadvantage of adding indexes to tables in RDBMS?

You might also like