---
title: "Golang的slice陷阱"
author: "jayeye"
date: "2014-01-22T15:39:27Z"
tags: []
categories: ["编程语言"]
slug: "golang-slice"
draft: false
lastmod: "2014-01-22T15:39:27Z"
id: 2008256
url: "https://jayeye.iteye.com/blog/2008256"
---

```c

package main

import "fmt"
func main() {
	arr := []int{1, 2, 3, 4, 5}
	slice := arr[1:2]
	slice = append(slice, 6, 7, 8)
	fmt.Println(slice)
	fmt.Println(arr)
}

```

输出：

```c

[2 6 7 8]
[1 2 6 7 8]

```

建议：不要对slice类型的参数进行append