Predeclared Types and Declarations Flashcards
What are the predeclared types in Go?
Booleans, integers, floats, and strings.
What is the zero value in Go?
The default value for an uninitialized variable.
What are literals in Go?
Untyped values like numbers, characters, and strings.
How are integer literals written in Go?
In base 10, with optional underscores (e.g., 1_234).
What are the two types of string literals in Go?
Interpreted (double quotes) and raw (backticks).
What values can a boolean have in Go?
true and false.
What is the zero value for a boolean in Go?
false.
What are some integer types in Go?
int8, int16, int32, int64, uint8, uint16, uint32, uint64, byte (uint8), int, uint.
What is the zero value for an integer in Go?
0.
How does division work with integers in Go?
It truncates towards zero.
What are the floating-point types in Go?
float32 and float64.
Why avoid == and != with floating-point numbers in Go?
Precision issues can cause unexpected results.
What is the zero value for a string in Go?
”” (empty string).
Are strings mutable in Go?
No, they are immutable.
What is a rune in Go?
An alias for int32, representing a Unicode code point.
Is type conversion automatic in Go?
No, it must be explicit.
What’s the difference between var and := in Go?
var declares variables with optional initializers; := is a short declaration with type inference, used in functions.
What can be declared with const in Go?
Compile-time values like literals, true/false, strings, and runes.
What is an untyped constant in Go?
A constant with no specific type, allowing flexible use.
What happens to unused local variables in Go?
They cause a compile-time error.