Go variables, constants, slices, maps, control flow, functions, multiple returns, defer and zero values.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- How do you declare a variable with explicit type in Go?
Show answer
Using the var keyword, e.g., var x int
- What does the := operator do in Go?
Show answer
It declares and initializes a variable with inferred type in one step (short declaration)
- Can you declare multiple variables at once using var in Go?
Show answer
Yes, var a, b, c int declares three int variables at once
- What is the blank identifier (_) used for when declaring variables?
Show answer
To ignore or discard a value, so the compiler does not require it to be used
- Does a Go program compile if you declare a variable but never use it?
Show answer
No, Go does not allow unused variables and will produce a compile error
- What keyword is used to declare a constant in Go?
Show answer
The const keyword, e.g., const PI = 3.14
- Are constants in Go always typed, or can they be untyped?
Show answer
Constants can be untyped. Untyped constants have a kind but no explicit type until assigned.
- What is the iota identifier used for in Go?
Show answer
iota generates successive integer constants, starting at 0 and incrementing with each const line
- How do you create an enumeration-style group of related constants?
Show answer
Use a const block with iota, e.g., const (RED = iota; BLUE; GREEN)
- What is the zero value for the int type in Go?
Show answer
0
- What is the zero value for the string type in Go?
Show answer
An empty string (empty double quotes)
- What is the zero value for the bool type in Go?
Show answer
false
- What is the zero value for a pointer type in Go?
Show answer
nil
- What is the zero value for a slice in Go?
Show answer
nil
- How do you declare a slice type in Go?
Show answer
Using square brackets without a fixed size, e.g., []int or []string