package main
import "fmt"
func main () {
    var n = []int{1,2,11,12}

    printSlice(n)

    for key,val := range n {
        fmt.Printf("%d => %d \n", key, val)
    }
}

func printSlice(x []int){
   fmt.Printf("len=%d cap=%d slice=%v\n",len(x),cap(x),x)
}
tbf1211(前端大神) - 2019-07-19 0 人
go test
ixiao9(iXiAo9) - 2019-06-27 0 人
defer_impact.go
// defer_impact.go
package main

import (
	"fmt"
)

func main() {
	fmt.Println(foo())
}

func foo() (result int) {
	defer func() {
		result++
	}()
	return 0
}

// go run defer_defer.go
// 1
taadis(前端大神) - 2019-06-14 0 人
defer_impact.go
// defer_filo.go
package main

import (
	"fmt"
)

func main() {
	foo()
}

func foo() {
	defer fmt.Println(1)
	defer fmt.Println(2)
	defer fmt.Println(3)
}

// go run defer_filo.go
// 3
// 2
// 1
taadis(前端大神) - 2019-06-14 0 人
defer_filo.go
// defer_defer.go
package main

import (
    "fmt"
)

func main() {
    foo()
}

func foo() {
    fmt.Println(1)
    defer fmt.Println(2)
    fmt.Println(3)
}

// go run defer_defer.go
// 1
// 3
// 2
taadis(前端大神) - 2019-06-14 0 人
defer_defer.go
// defer_parameters.go
package main

import (
	"fmt"
)

func main() {
	foo()
}

func foo() {
	number := 1
	defer fmt.Println(number)
	number = 2
	return
}
taadis(前端大神) - 2019-06-14 0 人
defer_parameters.go
没有了
1/4 下一页