go語言中的數組

來源:互聯網
上載者:User

標籤:指定   多維陣列   port   類型   部分   pac   不能   new   個數   

package main;import ("fmt")func main() {//聲明一個數組var a [3]int;a = [3]int{1, 2, 3};//聲明並賦值var b [3]int = [3]int{1, 2, 3};//聲明並賦值(省略類型)var c = [3]int{1, 2, 3};//聲明並賦值簡寫d := [3]int{1, 2, 3};//GO中將數組長度作為數群組類型的一部分//e與f是兩個類型不同的變數,他們之間不能進行賦值操作var e [2]int;var f [3]int;//指定下標初始零值,將最後一個元素設定為1var g [20]int = [20]int{19: 1};//使用...讓GO自動計算數組長度h := [...]int{1, 2, 3, 4, 5};//GO自動計算所需的數組長度,同變數gi := [...]int{19: 1};//數組的元素是指標,j數組的元素是指向int的指標aa := 1;bb := 2;j := [...]*int{&aa, &bb};//指向數組的指標k := [5]int{1, 2, 3, 4, 5};//m是一個指向數組的指標var m *[5]int = &k;//數組的比較n := [2]int{1, 2};o := [2]int{1, 2};//通過new返回一個指向數組的指標p := new([2]int);//也可以使用[]進行賦值p[0], p[1] = 1, 2;//多維陣列,二行二列q := [2][2]int{{1, 2}, {3, 4}};//自動計算多維陣列,必須是頂級r := [...][2]int{{1, 2}, {3, 4}, {5, 6}};fmt.Printf("%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n", a, b, c, d, e, f, g, h, i, j, m);//進行數組比較fmt.Println(n == o);fmt.Println(p);fmt.Println(q);fmt.Println(r);}

  

go語言中的數組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.