상수 선언

1. const 사용 - 직접 상수 타입을 선언하여 주는 방법

const 상수명 데이터_타입 = "내용"

package main

import "fmt"

func main() {
	const name string = "AshCost"
	fmt.Println(name)
}

2. 축약어 사용 - 상수 타입이 자동으로 선언 되는 방식, 첫번째 value에 따라 변함.

상수명 := "내용"

package main

import "fmt"

func main() {
	name := "AshCost"
	fmt.Println(name)
}
  • string type

  • bool type

  • int type

해당 축약어 방식은 function 내 에서만 사용할 수 있다.

profile
King of King

0개의 댓글