Go

Language Fundamentals & Types Interview Questions

39 Go interview questions on language fundamentals & types, with detailed answers and code.

0/577 known
39 questions
Language Fundamentals & TypesQ2Medium

new(T) works for any type. It allocates a zeroed T and returns a *T . make only works for slices, maps and channels. It initializes the runtime data structure behind…

Language Fundamentals & TypesQ3Hard

type Size int64 const ( _ = iota // iota = 0, skipped KB Size = 1 << (10 * iota) // iota = 1 MB // iota = 2: repeats the expression GB // iota = 3 ) const ( A, B = iota,…

Language Fundamentals & TypesQ6Medium

var db *sql.DB func initDB() error { db, err := sql.Open("postgres", dsn) // BUG: declares a new local db if err != nil { return err } return db.Ping() } // Later:…

Language Fundamentals & TypesQ8Hard

i := 0 s := []int{10, 20} i, s[i] = 1, 5 fmt.Println(i, s) a, b := 1, 2 a, b = b, a+b fmt.Println(a, b) Output: 1 [5 20] 2 3 A tuple assignment happens in two phases .…

Language Fundamentals & TypesQ11Medium

s := "héllo" fmt.Println(len(s)) fmt.Println(s[1]) fmt.Println(utf8.RuneCountInString(s)) for i, r := range s { fmt.Printf("%d:%c ", i, r) } Output: 6 195 5 0:h 1:é 3:l…

Language Fundamentals & TypesQ23Hard

Go has goto , but with two rules that keep it safe: It can't jump over a variable declaration if the variable would be in scope at the label. That would create a…

Language Fundamentals & TypesQ33Hard

arr := [3]int{1, 2, 3} for i, v := range arr { if i == 0 { arr[1] = 100 } fmt.Print(v, " ") } fmt.Println() sl := []int{1, 2, 3} for i, v := range sl { if i == 0 { sl[1]…

Next topicArrays, Slices, Maps & Strings