FlashKeepers

Go · College · College and University

Go I: Syntax and Types

Go variables, constants, slices, maps, control flow, functions, multiple returns, defer and zero values.

About this set

40 basic cards for College Go. It opens with "How do you declare a variable with explicit type in Go?" and "What does the := operator do in Go?". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

How do you declare a variable with explicit type in Go?
Show answerUsing the var keyword, e.g., var x int
What does the := operator do in Go?
Show answerIt 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 answerYes, var a, b, c int declares three int variables at once
What is the blank identifier (_) used for when declaring variables?
Show answerTo 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 answerNo, Go does not allow unused variables and will produce a compile error
What keyword is used to declare a constant in Go?
Show answerThe const keyword, e.g., const PI = 3.14
Are constants in Go always typed, or can they be untyped?
Show answerConstants can be untyped. Untyped constants have a kind but no explicit type until assigned.
What is the iota identifier used for in Go?
Show answeriota 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 answerUse a const block with iota, e.g., const (RED = iota; BLUE; GREEN)
What is the zero value for the int type in Go?
Show answer0
What is the zero value for the string type in Go?
Show answerAn empty string (empty double quotes)
What is the zero value for the bool type in Go?
Show answerfalse
What is the zero value for a pointer type in Go?
Show answernil
What is the zero value for a slice in Go?
Show answernil
How do you declare a slice type in Go?
Show answerUsing square brackets without a fixed size, e.g., []int or []string

25 more cards in the app

Study this set free