The _____ keyword is used to create a new instance of a struct in Go
- new
- make
- struct
- instance
The struct keyword is used to create a new instance of a struct in Go. For example, if you have a struct type defined as type Person struct { Name string }, you can create a new instance like this: p := Person{Name: "John"}. The new keyword is used to allocate memory for a variable and return a pointer to it, make is used for slices, maps, and channels, and instance is not a valid Go keyword for creating structs.
Loading...
Related Quiz
- How can you organize multiple Go files into a single package?
- Mocking interfaces can help to isolate _____ during testing.
- How do you detect and fix memory leaks in a Go program?
- Describe how you would use sub-benchmarks in Go.
- Describe a scenario where benchmark results might be misleading and how you would address it.