当前位置:网站首页>Small pit on the definition of two-dimensional or multi-dimensional array / slice in go language
Small pit on the definition of two-dimensional or multi-dimensional array / slice in go language
2022-04-22 15:50:00 【Mengo_ x】
Go A two-dimensional array of is an array of arrays , A two-dimensional slice is a slice of a slice .
First, a two-dimensional array can be defined as :
dp := [2][2]int{
}
But this The length must be a dead constant , If defined in this way, an error will be reported , Because variables are used .
m := 2
n := 2
dp := [m][n]int{
}
If you have to use variables , Then you can only use slices .
We all know , A one-dimensional slice of a specific length can be used make( []Type, size, cap ) To define , How to define a two-dimensional slice ?
The answer is that it can only be defined by the slice of the slice , That is, first define a two-dimensional slice of a dimension , Then a loop is used to define the slice of the slice :
leng := 4
a :=make([][]int ,leng)
for i:=0;i<4;i++{
a[i]=make([]int,leng)
}
Although this loop can be used with double loop values , However, it is not as convenient as other languages to define two-dimensional arrays , Must be from 0 Start the cycle .
Slices of more dimensions are the same .
版权声明
本文为[Mengo_ x]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221546084692.html
边栏推荐
- How redis solves the performance bottleneck caused by frequent command round trips!
- 短视频平台开发,自定义一个弹窗样式和内容
- SQL statement - multi table joint query
- 腾讯云堡垒机开启OTP认证
- sql语句———多表联查
- Sequential list -- basic implementation of one-way headless linked list
- Web automated testing
- 【里程碑】WireGuard系列文章(七):使用WireGuard和Netmaker创建Full Mesh网络
- Construction method and process of enterprise level knowledge management (km)
- Shell脚本中sed使用
猜你喜欢

How can AI intelligent video technology be applied to the scene of daily maintenance and supervision of cultural relics and historic buildings?

Do you know how to generate random numbers? (over 3000 words)
![[in depth understanding of tcallusdb technology] sample code of batch reading data - [generic table]](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[in depth understanding of tcallusdb technology] sample code of batch reading data - [generic table]
![[in depth understanding of tcallusdb technology] sample code for reading the data of the specified location in the list - [list table]](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[in depth understanding of tcallusdb technology] sample code for reading the data of the specified location in the list - [list table]

MySQL operator explanation and regular expression query

Recommendation of community operation books

Alibaba P9 handwritten 39 module redis core notes. I had a successful interview and got a salary increase of 7K

這個API Hub厲害了,收錄了釘釘企業微信等開放Api,還能直接調試 !
![[in depth understanding of tcallusdb technology] insert data example code - [generic table]](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[in depth understanding of tcallusdb technology] insert data example code - [generic table]

阿里P9手写39模块Redis核心笔记,吃透笔记我面试成功涨薪7K
随机推荐
短链接生成器,adf.ly、shorte.st、ouo.io、adfoc.us哪个更好,有哪些区别
Computer taskbar stuck
[in depth understanding of tcallusdb technology] asynchronous scanning data example code - [generic table]
Summary of redis small knowledge points (take a glance when you are bored)
Grafana 系列文章(九):开源云原生日志解决方案 Loki 简介
反转链表(AND)链表的中间结点
电脑任务栏卡住
[in depth understanding of tcallusdb technology] sample code for reading data according to some key field values - [generic table]
图形学101 矩阵变换(2~4节)
For the professional development of teacher Guo, write down your experience
Terraform best practices: typical file layout
SAP UI5 应用开发教程之七十一 - SAP UI5 页面的嵌套路由试读版
【里程碑】WireGuard系列文章(七):使用WireGuard和Netmaker创建Full Mesh网络
面试官:请说说==操作符和equals(),从基本数据类型和引用数据类型两个角度谈谈
Tencent cloud fortress machine opens OTP authentication
Vscode handles code merge conflicts
RF of mL: the kaggle competition uses the Titanic data set to establish an RF model to predict whether everyone is rescued or not
Is the account of digging money safe? How to handle it?
快速搭建属于你自己的WordPress博客站点【玩转华为云】
jsquery.xxx.js和jsquery.xxx.min.js的区别