Golang quiz questions - Part 04

This is the fourth part of the Go/Golang quiz. In this part, we will be given MCQ type questions and will have to choose the correct answer based on the question. Other quizzes have already been uploaded; to see those questions, go to the quiz area.

 

Golang quiz

 

 

1. what is the output of below code snippet

package main

import (
        "fmt"
        "time"
)

func instSum(arr []int) int {
        if 0 == len(arr) {
                return 0
        }
        time.Sleep(1)
        return instSum(arr[1:]) + arr[0]
}

func main() {
        arr := []int{1, 2, 3, 4, 5}
        sum := instSum(arr)
        fmt.Println("Sum of arr :", sum)
}




 

2. How to check go version?





 

3. what is the output of below code snippet?

package main

import "fmt"

func lenTest() {
        data := make([]int, 5)
        for i := 0; i < 3; i++ {
                data[i] = i
        }
        fmt.Println(len(data), cap(data), data)
}

func main() {
        lenTest()
}




 

4. what is the output of below code snippet?

package main

import "fmt"

func lenTest() {
        data := make([]int, 2)
        for i := 0; i < 3; i++ {
                data[i] = i
        }
        fmt.Println(len(data), cap(data), data)
}

func main() {
        lenTest()
}




Post a Comment

0 Comments