Can constants be of a complex data type, such as slices or structs, in Go?
- No
- Only if explicitly declared as 'complex' constants
- Only if they are part of a package-level constant block
- Yes
No, constants in Go must be simple types like numbers, strings, or booleans. They cannot be of complex types such as slices or structs. This is because constants must have a fixed value at compile-time, and complex types cannot be represented as fixed values at compile-time.
Loading...
Related Quiz
- Which package in Go provides built-in support for templates?
- You have a Go application that is experiencing memory leaks. How would you go about diagnosing and fixing the issue?
- What is the purpose of the http.HandleFunc function in Go's HTTP server package?
- What is the primary purpose of Protocol Buffers?
- How do you declare and initialize a map in Go?