This blog is a part of the Golang quiz, and here I've provided some simple slice and array questions that can assist you a lot while tackling huge issues. These are essential questions that most interviewers use to see how well you know your working programming language.
We made this post on golang Multiple Choice Questions so that you may answer them depending on your knowledge and then execute the code on your local system or go playground. If you have any problems, please let me know in the comments.
1. what is the output of below code snippet
package main
import (
"fmt"
)
func main() {
var x int
lstArray := [3]int{1, 2, 3}
x, lstArray = lstArray[0], lstArray[1:]
fmt.Println( x, lstArray)
}
2. what is the output of below code snippet
package main
import (
"fmt"
)
func main() {
var x int
lstArray := []int{1, 2, 3}
x, lstArray = lstArray[0], lstArray[1:]
fmt.Println( x, lstArray)
}
3. what is the output of below code snippet?
package main
import (
"fmt"
)
func main() {
var x int
lstArray := [...]int{1, 2, 3}
x, lstArray = lstArray[0], lstArray[1:]
fmt.Println(x, lstArray)
}
4. What is the output of below code snippet?
package main
import (
"fmt"
)
func main() {
x := [2]int{1,2}
r := [...]int{1,2}
fmt.Println(x==r)
}
5. What is the output of below code snippet?
package main
import (
"fmt"
)
func ElementChange(x [3]int) {
x[2] = 5
}
func main() {
x := [3]int{1, 2}
ElementChange(x)
fmt.Println(x)
}
6. What is the output of below code snippet?
package main
import (
"fmt"
)
func main() {
x := [...]string{1:"xyz", 2:"pqr"}
fmt.Println(x[0],x[1])
}
0 Comments