Curriculum Types & methods Structs exercise 3 · mcq
Structs
What does the bare declaration var u User produce, before any
field is written?
In TypeScript, an uninitialised User is undefined — you have
to assign a literal or get a runtime error reaching for u.name.
Go gives you a fully-formed value: every field zeroed to its
type's zero value, no undefined, no panic on access.
Pick the line that correctly describes Go's behaviour, given:
``go
type User struct {
name string
age int
ok bool
}
var u User
``
About this theme
type Foo struct { ... }. A struct is a typed record — fields and their types, nothing else. No methods on the struct itself (those come next). Field access with .. Struct literals can be positional or named; named is the only sane choice for anything with more than two fields.