当前位置:网站首页>使用make方法创建slice切片的坑
使用make方法创建slice切片的坑
2022-06-12 13:53:00 【Running SnaiL_】
先查看下面的代码
package main
import "fmt"
func main() {
ints := make([]int, 3)
ints = append(ints, 1)
fmt.Println(ints)
}
打印的结果是
[0 0 0 1]
因为使用 内置函数 make([]type, len) 创建slice 时 len参数视为初始长度,会自动初始化,这里我们使用的类型是int,所以初始化值为0 ,如果是指针类型 则初始化值为nil。
并不是我一开始设想的只是给slice一个内置的长度 ,后添加的元素会自动从0开始,这个坑主要是我使用java List的思想套入了golang中。
边栏推荐
- Void pointer (void*) usage
- Encryptor and client authenticate with each other
- SystemC time
- 【mysql进阶】查询优化原理与方案(六)
- 一种快速创建测试窗口的方法
- 阿里云开发板HaaS510报送设备属性
- TestEngine with ID ‘junit-vintage‘ failed to discover tests
- Démontage et modification de la machine publicitaire - décompression amateur
- PostgreSQL14安装使用教程
- [advanced MySQL] evolution of MySQL index data structure (IV)
猜你喜欢

【视频课】android studio物联网APP设计制作全套教程--国庆期间全掌握

公司运营中更注重转化的出价策略,如何实现? —Google sem

编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构

Is MySQL query limit 1000,10 as fast as limit 10? How to crack deep paging

【SemiDrive源码分析】【X9芯片启动流程】25 - MailBox 核间通信机制介绍(代码分析篇)之 RPMSG-IPCC RTOS & QNX篇
![[advanced MySQL] evolution of MySQL index data structure (IV)](/img/eb/e32387b172eb4c3a4152dbc3b0cb8f.png)
[advanced MySQL] evolution of MySQL index data structure (IV)

Web3.0, the era of "stimulating creativity"

Scyther工具形式化分析Woo-Lam协议

拆改广告机---业余解压

CSDN博客积分规则
随机推荐
Transmission and response of events and use cases
Acwing: topology sequence
TestEngine with ID ‘junit-vintage‘ failed to discover tests
[WUSTCTF2020]颜值成绩查询-1
肝了一个月的原创小袁个人博客项目开源啦(博客基本功能都有,还包含后台管理)
Compile and install lamp architecture of WordPress and discuz for multi virtual hosts based on fastcgi mode
Codeforces 1629 A. download more RAM - simple greed
简述CGI与FASTCGI区别
2000. reverse word prefix
[semidrive source code analysis] [x9 chip startup process] 25 - Introduction to mailbox inter core communication mechanism (code analysis) rpmsg-ipcc RTOS & QNX
[video lesson] a full set of tutorials on the design and production of Android studio Internet of things app -- all mastered during the National Day
Dismantle and modify the advertising machine - Amateur decompression
【mysql进阶】索引分类及索引优化方案(五)
Shell notes
Debug code to quickly locate the error location
Is MySQL query limit 1000,10 as fast as limit 10? How to crack deep paging
浅谈中国程序员为什么要跳槽?
Now you must know the pointer
CSDN blog points rule
注重点击,追求更多用户进入网站,可以选择什么出价策略?