언어/Go

go언어 const

파아랑새 2016. 2. 20. 12:51

const에 대해서(c언어 동일 python은 상수선언이 없다고 나온다.)


package main
import (
"fmt"
"math/rand"
)
func main() {
const x int = rand.Intn(10)
fmt.Print(x)
}

# command-line-arguments
./test.go:7: const initializer rand.Intn(10) is not a constant

----------------------------------------------------------------------------------

package main
import (
"fmt"
//"math/rand"
)
func main() {
//const x int = rand.Intn(10)
const x int = 10
fmt.Print(x)
x = 20
fmt.Print(x)
}

# command-line-arguments
./test.go:10: cannot assign to x