Golang Data Types & Zero Values Quiz

Golang
0 Passed
0% acceptance

40 comprehensive questions on Go's built-in types, zero values, type inference, conversions vs casting, and aliased types — with 20 code examples to master type safety and initialization.

40 Questions
~80 minutes
1

Question 1

What are Go's basic built-in types?

A
bool, string, and numeric types (int, uint, float, complex)
B
Only int, float, and string
C
Classes and interfaces only
D
Dynamic types only
2

Question 2

What is the zero value of an int variable?

A
0
B
nil
C
undefined
D
Compilation error
3

Question 3

What is the zero value of a bool variable?

A
false
B
true
C
0
D
nil
4

Question 4

What is the zero value of a string variable?

A
"" (empty string)
B
nil
C
0
D
undefined
5

Question 5

What is the zero value of a pointer variable?

A
nil
B
0
C
null
D
undefined
6

Question 6

What will this code print?

go
package main

import "fmt"

func main() {
    var x int
    var y bool
    var z string
    fmt.Println(x, y, z)
}
A
0 false
B
0 true ""
C
Compilation error
D
undefined undefined undefined
7

Question 7

What is type inference in Go?

A
The compiler determines the type from the assigned value
B
You must always specify types explicitly
C
Types are inferred at runtime
D
Only for constants
8

Question 8

What will this code output?

go
package main

import "fmt"

func main() {
    x := 42
    y := 3.14
    z := "hello"
    fmt.Printf("%T %T %T\n", x, y, z)
}
A
int float64 string
B
int32 float32 string
C
Compilation error
D
var var var
9

Question 9

What is the difference between conversion and casting?

A
Conversion is safe type change, casting is reinterpretation
B
They are the same in Go
C
Casting is for primitives, conversion for objects
D
Go only has casting
10

Question 10

What will this conversion do?

go
package main

import "fmt"

func main() {
    var x int32 = 1000
    var y int16 = int16(x)
    fmt.Println(y)
}
A
1000
B
Compilation error
C
0
D
Truncated value
11

Question 11

What is an aliased type in Go?

A
A new name for an existing type using type keyword
B
A pointer to another type
C
A generic type
D
An interface implementation
12

Question 12

What will this code print?

go
package main

import "fmt"

func main() {
    type Celsius float64
    var temp Celsius = 20.5
    fmt.Printf("%T %v\n", temp, temp)
}
A
main.Celsius 20.5
B
float64 20.5
C
Compilation error
D
Celsius 20.5
13

Question 13

What is the zero value of a slice?

A
nil
B
empty slice
C
0
D
undefined
14

Question 14

What is the zero value of a map?

A
nil
B
empty map
C
{}
D
0
15

Question 15

What will this code output?

go
package main

import "fmt"

func main() {
    var s []int
    var m map[string]int
    fmt.Println(s == nil, m == nil)
}
A
true true
B
false false
C
Compilation error
D
true false
16

Question 16

What happens when you convert a float to int?

go
package main

import "fmt"

func main() {
    var f float64 = 3.9
    var i int = int(f)
    fmt.Println(i)
}
A
3 (truncated)
B
4 (rounded)
C
Compilation error
D
3.9
17

Question 17

What is the output of this type inference example?

go
package main

import "fmt"

func main() {
    a := 1
    b := 2.0
    c := a + int(b)
    fmt.Println(c)
}
A
3
B
3.0
C
Compilation error
D
1 + 2.0
18

Question 18

What is the zero value of a channel?

A
nil
B
closed channel
C
empty channel
D
0
19

Question 19

What will this aliased type code do?

go
package main

import "fmt"

type Kilograms float64

type Pounds float64

func main() {
    var kg Kilograms = 10
    var lbs Pounds = Pounds(kg)
    fmt.Println(lbs)
}
A
Compilation error
B
10
C
0
D
Type assertion needed
20

Question 20

What is the output of this zero value demonstration?

go
package main

import "fmt"

func main() {
    var (
        i int
        f float64
        b bool
        s string
        p *int
    )
    fmt.Printf("%v %v %v %q %v\n", i, f, b, s, p)
}
A
0 0 false "" <nil>
B
0 0 true "" 0
C
Compilation error
D
undefined undefined undefined undefined undefined
21

Question 21

What is the range of int in Go?

A
Platform-dependent (32 or 64 bits)
B
Always 32 bits
C
Always 64 bits
D
8 bits
22

Question 22

What will this conversion output?

go
package main

import "fmt"

func main() {
    var x int = 257
    var y byte = byte(x)
    fmt.Println(y)
}
A
1 (overflow)
B
257
C
Compilation error
D
0
23

Question 23

What is the zero value of a function variable?

A
nil
B
empty function
C
0
D
panic
24

Question 24

What will this type inference do?

go
package main

import "fmt"

func main() {
    x := []int{1, 2, 3}
    fmt.Printf("%T\n", x)
}
A
[]int
B
interface{}
C
Compilation error
D
var
25

Question 25

What is the output of this string conversion?

go
package main

import "fmt"

func main() {
    var i int = 65
    var s string = string(i)
    fmt.Println(s)
}
A
A
B
65
C
Compilation error
D
65 as string
26

Question 26

What is the zero value of a rune?

A
0 (null character)
B
nil
C
'\0'
D
undefined
27

Question 27

What will this aliased type code do?

go
package main

import "fmt"

type MyInt int

func main() {
    var x MyInt = 42
    var y int = int(x)
    fmt.Println(y)
}
A
42
B
Compilation error
C
0
D
MyInt(42)
28

Question 28

What is the output of this float conversion?

go
package main

import "fmt"

func main() {
    var f float32 = 1.5
    var i int = int(f)
    fmt.Println(i)
}
A
1
B
2
C
1.5
D
Compilation error
29

Question 29

What is the zero value of an array?

A
Array with zero values for each element
B
nil
C
empty array
D
undefined
30

Question 30

What will this type assertion do?

go
package main

import "fmt"

func main() {
    var i interface{} = 42
    s := i.(string)
    fmt.Println(s)
}
A
Panic at runtime
B
42
C
Compilation error
D
"42"
31

Question 31

What is the output of this complex type inference?

go
package main

import "fmt"

func main() {
    x := 1 + 2.0
    fmt.Printf("%T %v\n", x, x)
}
A
float64 3
B
int 3
C
Compilation error
D
3.0 3.0
32

Question 32

What is the zero value of a struct?

A
Struct with zero values for all fields
B
nil
C
empty struct
D
undefined
33

Question 33

What will this conversion do?

go
package main

import "fmt"

func main() {
    var b []byte = []byte("hello")
    s := string(b)
    fmt.Println(s)
}
A
hello
B
Compilation error
C
[104 101 108 108 111]
D
nil
34

Question 34

What is the output of this aliased type example?

go
package main

import "fmt"

type Celsius float64
type Fahrenheit float64

func main() {
    var c Celsius = 20
    var f Fahrenheit = Fahrenheit(c + 32)
    fmt.Printf("%T %v\n", f, f)
}
A
main.Fahrenheit 52
B
float64 52
C
Compilation error
D
main.Celsius 52
35

Question 35

What is the zero value of a complex number?

A
(0+0i)
B
nil
C
0
D
undefined
36

Question 36

What will this code print?

go
package main

import "fmt"

func main() {
    var x uint8 = 255
    x++
    fmt.Println(x)
}
A
0 (overflow)
B
256
C
Compilation error
D
255
37

Question 37

What is the output of this type inference with constants?

go
package main

import "fmt"

func main() {
    const x = 42
    y := x
    fmt.Printf("%T %v\n", y, y)
}
A
int 42
B
untyped int 42
C
Compilation error
D
42 42
38

Question 38

What is the zero value of a rune?

A
0 (null character)
B
nil
C
'\0'
D
undefined
39

Question 39

What will this conversion do?

go
package main

import "fmt"

func main() {
    var s string = "hello"
    b := []byte(s)
    fmt.Println(b)
}
A
[104 101 108 108 111]
B
hello
C
Compilation error
D
nil
40

Question 40

Why does Go require explicit conversions?

A
To prevent bugs from implicit type changes and make conversions visible
B
To make code slower
C
To match C++ style
D
To allow any conversion

QUIZZES IN Golang