Given the following Go program: package mainimport “fmt”type T struct { S string }func (t *T) test(){ if t==nil { fmt.Println(“nil underlying value”) } else { fmt.Println(t.S) }}type Test interface{ test()}var myTest Testfunc main(){ var t *T myTest = t myTest.test()} Which of the following statements is true about the given program?
Blog
Given the following function signature and function definiti…
Given the following function signature and function definition: func calculate(x int) int func test() { ch := make(chan int) go func() { ch
Consider the following Go code fragment, assuming that varia…
Consider the following Go code fragment, assuming that variable any has been declared to be of the empty interface type. if value, ok := any.(int); ok { value = value + 2 } else if value, ok := any.(float64); ok { value = value + 2.5 } else if value, ok := any.(string); ok { value = value + “2” } Rewrite the code fragment above as an equivalent type switch statement.
Any two function values in Go can be compared to each other.
Any two function values in Go can be compared to each other.
Complete the following Go code fragment so that the Balance…
Complete the following Go code fragment so that the Balance field in the Account struct is safe for use in concurrent program, i.e., only one goroutine can access the Account’s Balance at a time. Don’t type unnecessary whitespaces in your answers. Each blank you need to fill can contain no more than one statement. type Account struct{ guard_Balance [sync] //use this variable to guard Balance Balance int32}func Update(acc Account, amount int32){ [lock] acc.Balance += amount [unlock]}
Assume that variable s has been declared as a string variabl…
Assume that variable s has been declared as a string variable and initialized to a non-empty string literal. Which of the following statement will cause a syntax error? a := s[0] //statement As[0] = ‘B’ //statement B
Which is a valid function in Go that returns the results of…
Which is a valid function in Go that returns the results of swapping two integers?
Given the following Go code fragment: type Point struct { …
Given the following Go code fragment: type Point struct { X, Y float64}type Integer inttype Test interface{ test()}func (p Point) test() {return }func (n Integer) test() {return }var myTest Test Which of the following Go statements is legal, assuming they are in the same package as the given code fragment?
What looping construct(s) does Go have?
What looping construct(s) does Go have?
Assuming a package named pkg has a function named print, whi…
Assuming a package named pkg has a function named print, which starts with a lower case letter. Then when you import the pkg package in your program, you can call the function pkg.print.