go array數組slice切片實例

package main

import (
	"flag"
	"fmt"
)

const (
	szie int = 5
)

var p *int = flag.Int("p", 0, "ente page")
var s *int = flag.Int("s", 10, "ente szie")

func main() {
	flag.Parse()

	data := make([]int, *s)
	for i := 1; i < *s; i++ {
		data[i] = i
	}
	newd := make([]int, szie)
	if *p <= 0 {
		newd = data[:szie]
	} else {
		m := *p * szie

		if m <= *s {
			j := m - szie
			newd = data[j:m]
		}
	}
	fmt.Printf("%v", newd)
}

你可能感兴趣的:(array,slice,Go,分頁)