Predict the output of the following code snippet.

package main

import (
	"fmt"
)

func sport() {
	fmt.Printf("In sport function->")
}
func getSport(arr []string, ind int) string {
	sport()
	if len(arr) > ind {
		return arr[ind]
	} else {
		panic("Index out of bound")
	}
}
func defFunc() {
	fmt.Printf("Deferred Function called->")
	re := recover()
	if re != nil {
		fmt.Printf(" Error from Recovery : %v", re)
	}
}
func main() {
	defer defFunc()
	sportArr := []string{"Cricket", "Hockey", "Football"}
	getSport(sportArr, 3)
}

Compilation error

Runtime error

Deferred Function called-> In sport function -> Error from Recovery : Index out of bound

In sport function->Deferred Function called-> Error from Recovery : Index out of bound

Verified Answer
Correct Option - d

To get all Go Programming Language - Assessment Exam questions Join Group https://bit.ly/infy_premium_group

We're passionate about offering best placement materials and courses!! A one stop place for Placement Materials. We daily post Offcampus updates and Placement Materials.

Qtr No. 213, New Town Yehlanka Indore 454775

admin@prepflix.in