Determine the output of each fmt.Println() statement in the…
Determine the output of each fmt.Println() statement in the following Go code block by selecting the correct answer at the end of the fmt.Println() statement. s := []int{11, 12, 13, 14, 15, 16} s = s[:0] fmt.Println(“len=”, len(s), “cap=”, cap(s)) //output: [output2] s = s[:5] fmt.Println(“len=”, len(s), “cap=”, cap(s)) //output: [output3] s = s[3:] fmt.Println(“len=”, len(s), “cap=”, cap(s)) //output: [output4]
Read DetailsConsider the following Go code block: var names = []string{“…
Consider the following Go code block: var names = []string{“Alex”, “Bob”, “Chris”}for _, s := range names{ fmt.Printf(“%s,”, s) /* note: no space after the comma in the format string */} Write the output of the code block above exactly as it appears on screen: [output]
Read DetailsConsider the following main function in a Go program which c…
Consider the following main function in a Go program which crashes (panic) eventually: func main(){ fmt.Println(“Start”) defer fmt.Println(“Deferred call”) panic(“Crashed”)} The deferred call in the main function will still be executed when this program is run.
Read DetailsComplete the following Go code block so that it declares gra…
Complete the following Go code block so that it declares grades as a map that maps student names to their grades and print out all student names and their grades (DON’T type unnecessary spaces in your answers): grades := [maptype]{“Alex”: 93.2, “Bob”: 64.1, “Chris”: 70.5} for [namegrade] := [range] grades { fmt.Printf(“%s has a grade of %0.1f%%\n”, name, grade) } Expected output: Alex has a grade of 93.2% Bob has a grade of 64.1% Chris has a grade of 70.5%
Read DetailsDefine a Go’s struct type named BinaryTree that represents a…
Define a Go’s struct type named BinaryTree that represents a binary tree. This struct must have three fields: one field of type int that represents the value at the root of the tree, one field is a pointer pointing to the left subtree which is also of type BinaryTree one field is a pointer pointing to the right subtree which is also of type BinaryTree
Read Details