当前位置:网站首页>Golang foundation -- slicing several declaration methods
Golang foundation -- slicing several declaration methods
2022-06-30 12:52:00 【The hunter is eating meat】
1, Statement slice It's a slice , No space was allocated after the declaration ,len yes 0
var slice1 []int
2, Statement slice It's a slice , And initialize , The default value is 123, The length is 3
slice1 := []int{
1,2,3}
3, Statement slice It's a slice , Adopted after declaration make Distribute 3 Space , The initialization value is 0
var slice1 []int = make([]int,3)
4, adopt := Automatically deduce and judge slice It's a slice , adopt make Distribute 3 Space , The default value is 0
slice1 := make([]int,3)
Here is the complete executable code , Self testing ( The following code has a syntax error )
package main
import "fmt"
func main(){
// 1, Statement slice It's a slice , When only := No space was allocated after the declaration ,len yes 0
var slice1 []int
// 2, Statement slice It's a slice , And initialize , The default value is 123, The length is 3
slice2 := []int{
1,2,3}
// 3, Statement slice It's a slice , Assign after declaration 3 Space , The default value for initialization is 0
var slice3 []int = make([]int,3)
// 4, adopt := Deduce slice It's a slice
slice4 := make([]int,3)
fmt.Printf("len = %d","slice = %v\n",len(slice1),slice)
// %v Yes, print out all details
// Judge a slice Is it empty
if slice3 == nil {
fmt.Println("slice1 It's an empty slice ")
}else{
fmt.Println("slice1 There is room ")
}
}
边栏推荐
- [QNX Hypervisor 2.2用户手册]6.2.3 Guest与外部之间通信
- Android development interview real question advanced version (with answer analysis)
- JMeter性能测试工作中遇到的问题及剖析,你遇到了几个?
- kubeedge的核心理念
- Substrate 源码追新导读: 修复BEEFY的gossip引擎内存泄漏问题, 智能合约删除队列优化
- 独立站即web3.0,国家“十四五“规划要求企业建数字化网站!
- How to use AI technology to optimize the independent station customer service system? Listen to the experts!
- Can the polardb MySQL fees for RDS MySQL data migration be transferred?
- 【一天学awk】正则匹配
- FlinkSQL自定义UDATF实现TopN
猜你喜欢

Sarsa notes

Dark horse notes - common date API

【驚了】迅雷下載速度竟然比不上虛擬機中的下載速度

Unity脚本的基础语法(1)-游戏对象的常用操作

【OpenGL】OpenGL Examples

7 lightweight and easy-to-use tools to relieve pressure and improve efficiency for developers, and help enterprises' agile cloud launch | wonderful review of techo day

MATLAB小技巧(22)矩阵分析--逐步回归
![[qnx hypervisor 2.2 user manual]6.2.3 communication between guest and external](/img/ca/9065325ce8882d95fb24c82fb62abc.png)
[qnx hypervisor 2.2 user manual]6.2.3 communication between guest and external

你想要的异常知识点都在这里了

Four ways for flinksql to customize udtf
随机推荐
第十三章 信号(三)- 示例演示
postman 自动生成 curl 代码片段
Wechat launched the picture big bang function; Apple's self-developed 5g chip may have failed; Microsoft solves the bug that causes edge to stop responding | geek headlines
Introduction to the novelty of substrat source code: indexing of call calls and fully completing the materialization of storage layer
【一天学awk】正则匹配
Idea has a new artifact, a set of code to adapt to multiple terminals!
Vision based robot grasping: from object localization, object pose estimation to parallel gripper grasping estimation
微信小程序报错:TypeError: Cannot read property ‘setData‘ of undefined
QT implementation dynamic navigation bar
Js根据相同值将数组转换为二维数组
全面解析免费及收费SSH工具的基本特性和总结
Questionnaire star questionnaire packet capturing analysis
How to select an OLAP database engine?
力扣之螺旋矩阵,一起旋转起来(都能看懂)
[one day learning awk] use of built-in variables
golang 基础 —— 字符串 与 int 、int64 互转
【 surprise】 la vitesse de téléchargement de Thunderbolt n'est pas aussi rapide que celle de la machine virtuelle
【OpenGL】OpenGL Examples
Flink SQL console, group not recognized_ Concat function?
JMeter性能测试工作中遇到的问题及剖析,你遇到了几个?