In Go, what is the difference between 'var' and ':=' when declaring variables?
- Declares a constant
- Declares a variable and assigns a value without specifying its type
- Declares a variable with a shorthand syntax
- Declares a variable with an explicit type
In Go, var is used to declare variables with an explicit type, whereas := is a shorthand syntax that both declares a variable and assigns a value to it without needing to specify the type explicitly. This shorthand syntax is only available within functions, where type inference can be used.
Loading...
Related Quiz
- In a large Go project, you need to represent employees with different roles and permissions. How would you structure your structs to accommodate this requirement?
- What is the difference between an array and a slice in Go?
- What is the difference between buffered and unbuffered channels in Go?
- Can 'panic()' be called inside a deferred function in Go?
- What are atomic operations and how are they provided in the sync package?