当前位置:网站首页>Create a slice slice pit using the make method
Create a slice slice pit using the make method
2022-06-12 14:01:00 【Running SnaiL_】
First look at the following code
package main
import "fmt"
func main() {
ints := make([]int, 3)
ints = append(ints, 1)
fmt.Println(ints)
}
The result of printing is
[0 0 0 1]
Because use Built in functions make([]type, len) establish slice when len The parameter is treated as the initial length , Will be initialized automatically , The type we use here is int, So the initialization value is 0 , If it's a pointer type Then the initialization value is nil.
It's not that what I imagined at the beginning was just to slice A built-in length , The added elements will be automatically added from 0 Start , This pit is mainly used by me java List The idea of golang in .
边栏推荐
- Programmer interview golden classic good question / interview question 01.05 Edit once
- Convert the string to hexadecimal string and display it
- Xcode debugging OpenGLES
- After reading the question, you will point to offer 16 Integer power of numeric value
- 280 weeks /2171 Take out the least number of magic beans
- 动态搜索广告智能查找匹配关键字
- Knowledge of wireless card driver
- 阿里云开发板vscode开发环境搭建
- 工具笔记 —— 常用自定义工具类(正则,随机数等)
- Tlm/systemc: TLM socket binding problem
猜你喜欢
Understanding recursion
Lua tvalue structure
Transmission and response of events and use cases
Web3.0, the era of "stimulating creativity"
Alicloud development board vscode development environment setup
Talk about the top 10 classic MySQL errors
CSDN blog points rule
Codeforces 1629 F2. Game on sum (hard version) - Yang Hui's triangle, violence, finding rules
什么是自动出价?它的优势是什么?
SystemC common errors
随机推荐
工具笔记 —— 常用自定义工具类(正则,随机数等)
【SemiDrive源码分析】【X9芯片启动流程】26 - R5 SafetyOS 之 LK_INIT_LEVEL_TARGET 阶段代码流程分析(TP Drvier、Audio Server初始化)
Cdeforces 1638 C. inversion graph - simple thinking
Fourteen week assignment
SystemC common errors
【mysql进阶】查询优化原理与方案(六)
Wait function in SystemC
Recursion of subviews of view
OAuth2学习中的一些高频问题的QA
单总线温度传感器18B20数据上云(阿里云)
Implementation of Ackermann function with simulated recursion
SystemC learning materials
Codeforces 1629 F2. Game on sum (hard version) - Yang Hui's triangle, violence, finding rules
Codeforces 1637 B. mex and array - reading, violence
Shell脚本到底是什么高大上的技术吗?
My resume.
Codeforces 1629 E. grid XOR - simple thinking
公司运营中更注重转化的出价策略,如何实现? —Google sem
拆改廣告機---業餘解壓
Relevant knowledge points of cocoapods