๋ฐ์ํ
Zero values
๋ช ์์ ์ธ ์ด๊น๊ฐ ์์ด ์ ์ธ๋ ๋ณ์๋ ๊ทธ๊ฒ์ zero value ๊ฐ ์ฃผ์ด์ง๋ค.
zero value ๋ ๋ค์๊ณผ ๊ฐ๋ค.
- ์ซ์ Type์๋ 0
- Boolean Type์๋ False
- String์๋ "" (๋น ๋ฌธ์์ด)
Nil slices (nil ์ฌ๋ผ์ด์ค)
Slice์ zero value๋ nil ์ด๋ค.
nil Slice์ ๊ธธ์ด(length)์ ์ฉ๋(capacity)์ 0์ด๋ฉฐ, ๊ธฐ๋ณธ ๋ฐฐ์ด์ ๊ฐ์ง๊ณ ์์ง ์๋ค.
์์
package main
import "fmt"
func main() {
var s []int
fmt.Println(s, len(s), cap(s))
if s == nil {
fmt.Println("nil!")
}
}
[์ฐธ๊ณ ์ฌ์ดํธ - a Tour of Go]
๋ฐ์ํ
'Data Base > Go' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Golang] C์ while = Go์ for (0) | 2021.11.01 |
---|---|
[Golang] for ๋ฐ๋ณต๋ฌธ (0) | 2021.11.01 |
[์ฝ๊ณ ๋น ๋ฅธ Go ์์ํ๊ธฐ] #1.11 Structs (0) | 2021.10.29 |
[์ฝ๊ณ ๋น ๋ฅธ Go ์์ํ๊ธฐ] #1.10 Maps (0) | 2021.10.29 |
[์ฝ๊ณ ๋น ๋ฅธ Go ์์ํ๊ธฐ] #1.9 Arrays and Slice (0) | 2021.10.29 |
๋๊ธ