Back to questions
JuniorTheoryCommon
What happens when this program is built and run?
package main
import "fmt"
const limit = 10
func main() {
n := 3
limit = n
fmt.Println(limit)
}It does not compile
- Expecting
3:constdeclares a value fixed at compile time, solimit = nis refused; only avaror:=variable takes a new value. - Expecting
10or a run-time error: the assignment is not skipped at run time, the compiler rejects it withcannot assign to limit.
- What is the difference between a typed and an untyped constant in Go?
- When does
:=re-use an existing variable versus declare a new one?