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

Go Test For Candidates

The document presents a test for candidates on Go programming language, featuring multiple-choice questions about Goroutines, memory usage of structs, select statements, panic and recover functions, channel operations, and Goroutine management. Each question requires selecting the correct answer from four options. The test assesses the candidates' understanding of key concepts in Go.

Uploaded by

Denies Kresna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Go Test For Candidates

The document presents a test for candidates on Go programming language, featuring multiple-choice questions about Goroutines, memory usage of structs, select statements, panic and recover functions, channel operations, and Goroutine management. Each question requires selecting the correct answer from four options. The test assesses the candidates' understanding of key concepts in Go.

Uploaded by

Denies Kresna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

GO TEST FOR CANDIDATES: Choose the right answer to the questions

below.

1. What is the primary purpose of Goroutines in Go?

a. To handle errors
b. To define data structures
c. To enable concurrent execution of functions
d. To declare interfaces

2. In Go (Golang), consider a struct named SimpleStruct that contains only two


fields: an int and a bool. On a 64-bit system, what is the memory usage of an
instance of the SimpleStruct struct, For this question, ignore any potential
memory alignment and padding effects.

a. 9 bytes
b. 12 bytes
c. 6 byte
d. 8 bytes

3. What is the role of the select statement when used with channels in Go?

a. Does not allow on multiple channel operations


b. Does not block until one of the cases from one of the channels can run
c. To allow waiting on multiple channel operations
d. Blocks until one of the cases from one of the channels can run

4. What does the panic() function do in Go? (knockout)

a. Handles runtime errors


b. Recovers from a panic
c. Gracefully fails the application
d. Halts the application

5. What is the output of the following code snippet?

package main

import "fmt"

func main() {
ch := make(chan int, 1)
ch <- 1
ch <- 2
fmt.Println(<-ch)
fmt.Println(<-ch)
}

a. prints 1 and 2
b. prints 1 and 1
c. throws a runtime error
d. program gets stuck

6. What does the recover() function return when called within a deferred
function after a panic in Go?

a. The panic value


b. The error message
c. The number of active Goroutines
d. Nothing; it cannot be used after a panic

7. In Go, what is the role of the close() function when used with a channel?

a. Deallocates the channel


b. Sends a value to the channel
c. Closes the channel for further sends
d. Closes the channel for further receives

8. I want to stop Goroutine A from Goroutine B. Is there a way to do that?

a. Yes, using return keyword


b. Yes, by closing a channel
c. No it is not possible to do so
d. None of the above

You might also like