0
0
Goprogramming~5 mins

Zero values in Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a zero value in Go?
A zero value is the default value a variable has when it is declared but not explicitly initialized. It depends on the variable's type.
Click to reveal answer
beginner
What is the zero value of an int in Go?
The zero value of an int is 0.
Click to reveal answer
beginner
What is the zero value of a string in Go?
The zero value of a string is an empty string "".
Click to reveal answer
beginner
What is the zero value of a bool in Go?
The zero value of a bool is false.
Click to reveal answer
beginner
What is the zero value of a pointer type in Go?
The zero value of a pointer is nil, meaning it points to nothing.
Click to reveal answer
What happens if you declare a variable in Go without assigning a value?
AIt is automatically assigned 1.
BIt causes a compile error.
CIt contains random data.
DIt gets the zero value of its type.
What is the zero value of a float64 in Go?
A1.0
B0.0
C"" (empty string)
Dnil
Which of these is NOT a zero value in Go?
A"0" for string
B0 for int
Cnil for pointer
Dfalse for bool
What is the zero value of a slice in Go?
AAn empty slice with length 0
BA slice with one element 0
Cnil
DA slice with random values
Why are zero values useful in Go?
AThey prevent variables from having garbage values.
BThey make the program slower.
CThey force you to always initialize variables.
DThey cause runtime errors.
Explain what zero values are in Go and give three examples.
Think about what happens when you declare a variable without setting it.
You got /2 concepts.
    Why does Go use zero values for uninitialized variables? How does this help programmers?
    Consider how zero values affect program reliability.
    You got /3 concepts.