프로그래밍/Go(golang) 프로그래밍
Go[golang] 변수 기본값
jeet95
2022. 6. 30. 02:03
Go 변수 초기 기본값
https://go.dev/ref/spec#The_zero_value
Each element of such a variable or value is set to the zero value for its type: false for booleans, 0 for numeric types, "" for strings, and nil for pointers, functions, interfaces, slices, channels, and maps.
초기 기본값
Booleans는 false
Numeric types(수 타입 : int, float)은 0
Strings(문자열)은 “” 빈 문자열
나머지 (포인터, 함수, 인터페이스 슬라이스 채널 그리고 맵)은 nil
var a int // 0
var b string // “”
var c bool // false
var d *int // nil