当前位置:网站首页>Go language array operation
Go language array operation
2022-04-23 12:56:00 【Play ha ha 527】
package main
import "fmt"
func main() {
// Declare and use arrays
var arr1 [5]string// The statement contains 5 String array of elements
arr2:= [5]string{
"a","b","c","d","e"}// Initialization contains 5 String array of elements
arr1=arr2// Array 2 Copy to array 1
fmt.Println(arr1)
fmt.Println(arr2)
// Above print results
//[a b c d e]
//[a b c d e]
var arr3 [3]*string// Declare array pointer variables of string type
arr4:=[3]*string{
new(string),new(string),new(string)}// Declare array pointer variables
*arr4[0]="red"
*arr4[1]="blue"
*arr4[2]="black"
arr3=arr4
for _,addr:=range arr3{
fmt.Println(*addr)
}
fmt.Println(*arr4[0],*arr4[1],*arr4[2])
/* The above print results red blue black red blue black*/
// Multidimensional arrays
var arr5 [3][2]int
arr6:=[3][2]int{
{
1,2},{
4,3},{
5,6}}// Initialize 2D array
arr5=arr6// Only two arrays with the same dimension can be assigned
fmt.Println(arr5)
fmt.Println(arr6)
/* Print the results [[1 2] [4 3] [5 6]] [[1 2] [4 3] [5 6]] */
arr6[0][1]=20
arr6[1][0]=30
fmt.Println(arr6)
var arr7 [2]int = arr6[0]
fmt.Print(arr7)
/* Print the results [[1 20] [30 3] [5 6]] [1 20] */
// Use values to pass , Pass large arrays between functions , Such as 1e6, There is only 10 An integer value
// Declare an array
var array [10]int
// Pass the array to the function foo
foo(array)// function foo Accept one 10 An array of integer values , Output results here
/* Output results [0 0 0 0 0 0 0 0 0 0] pass */
}
//main Out of function foo Function is used to pass an array
func foo(array [10]int) {
fmt.Println(array)
fmt.Println("pass")
}```**
版权声明
本文为[Play ha ha 527]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230615231509.html
边栏推荐
- NBIOT的AT指令
- leetcode:437. Path sum III [DFS selected or not selected?]
- 8 websites that should be known for product development to enhance work experience
- ZigBee CC2530 minimum system and register configuration (1)
- unity常见的问题(一)
- [csnote] ER diagram
- 4.DRF 权限&访问频率&过滤&排序
- 软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。
- 22. 括号生成
- Mysql8 installation
猜你喜欢
Object.keys后key值数组乱序的问题
数据库中的日期时间类型
Remote sensing image classification and recognition system based on convolutional neural network
云原生KubeSphere部署Redis
Deploying MySQL in cloud native kubesphere
Wonderful review | the sixth issue of "source" - open source economy and industrial investment
About the 'enum' enumeration type and structure.
Use source insight to view and edit source code
There is no need to crack the markdown editing tool typora
How to prevent the website from being hacked and tampered with
随机推荐
STM32 is connected to the motor drive, the DuPont line supplies power, and then the back burning problem
box-sizing
免费试用一个月的服务器,并附上教程
Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
Free and open source charging pile Internet of things cloud platform
Object.keys后key值数组乱序的问题
BUUCTF WEB [BUUCTF 2018]Online Tool
Sort out several uses of network IP agent
BUUCTF WEB [BUUCTF 2018]Online Tool
Common problems of unity (1)
Pre competition practice of TIANTI competition
[daily question] chessboard question
Luogu p3236 [hnoi2014] picture frame solution
Stm32cubeprogrammer basic instructions
SSM框架系列——Junit单元测试优化day2-3
有趣的IDEA插件推荐,给你的开发工作增添色彩
【csnote】ER图
Unlock openharmony technology day! The annual event is about to open!
Introduction to kubernetes
实现一个盒子在父盒子中水平垂直居中的几种“姿势”