Flashcards · Go · Free
Go flashcards, generated for you.
Example Go study cards to learn from right now — then generate a full set from your own notes (plus a practice quiz) and export to Quizlet or Anki. Free, no account needed.
Example Go flashcards
What is the syntax to declare a variable in Go?
Use `var name type` for explicit declaration, or `:=` for short declaration inside functions. Example: `var x int` or `x := 42`.
What is the zero value in Go?
The default value assigned to uninitialized variables. For int/float: 0, for string: "", for bool: false, for pointers/slices/maps/channels: nil.
What is the difference between `var` and `:=`?
`var` can be used at package or function scope; `:=` only works inside functions and infers the type. Both declare and initialize, but `:=` is more concise.
In Go, why does `i := i + 1` inside a loop sometimes fail?
If `i` was declared in an outer scope with `var`, you cannot redeclare it with `:=` in the inner scope. Use `i = i + 1` (assignment) instead.
What does `defer` do in Go?
`defer` postpones the execution of a function until the surrounding function returns. Deferred calls execute in LIFO order. Common use: file cleanup with `defer file.Close()`.
How does Go handle multiple return values and errors?
Functions return multiple values as a tuple. By convention, the last return value is an error: `func Foo() (int, error)`. Check with `if err != nil { ... }`.
What is a pointer in Go and how do you use it?
A pointer holds the memory address of a value. Declare with `*Type`, get address with `&value`, dereference with `*pointer`. Example: `var p *int; p = &x; *p = 10`.
Why do slices in Go behave unexpectedly when passed to functions?
Slices are passed by value, but contain a pointer to the underlying array. Modifying slice contents affects the original, but reassigning the slice (length/capacity) does not. To modify the slice header itself, pass `*[]T`.
What is the difference between `make` and `new` in Go?
`new(T)` allocates zero-valued memory and returns `*T`. `make(T)` initializes slices, maps, and channels and returns `T`. Use `make` for these types, `new` for simple allocation.
Why might a goroutine leak in Go and how do you prevent it?
A goroutine leaks if it's never scheduled to finish (e.g., blocked on a channel that never receives). Prevent by: closing channels, using timeouts with `context.WithTimeout`, or passing a done channel to signal completion.
Make your own Go study set
Flashcards for related topics
Studying Go to build with AI? MindloomHQ turns it into real skills — structured courses, agent projects, and certificates.
Explore MindloomHQ →