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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *