Files

40 lines
928 B
Go
Raw Permalink Normal View History

2018-12-18 15:20:37 +03:00
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
2019-10-30 19:34:44 +03:00
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus
2018-12-18 15:20:37 +03:00
package main
import "fmt"
func main() {
var array [2]int
// zero value of an array is zero-valued elements
fmt.Printf("array : %#v\n", array)
// nope: arrays are fixed length
// array[2] = 0
var slice []int
// zero value of a slice is nil
fmt.Println("slice == nil?", slice == nil)
// nope: they don't exist:
// _ = slice[0]
// _ = slice[1]
// len function still works though
fmt.Println("len(slice) :", len(slice))
// array's length is part of its type
fmt.Printf("array's type: %T\n", array)
// whereas, slice's length isn't part of its type
fmt.Printf("slice's type: %T\n", slice)
}