C++學習筆記(10)數組

來源:互聯網
上載者:User

標籤:

一、數組類似於vector,但是數組的大小確定以後,不能再往數組中添加元素。

二、不能將數組元素拷貝賦值給其他數組。

三、初始化數組:

  string a[2] = {"a","b"};

  string b[3] = "ab";註:字面值初始化數組會有一個Null 字元

四、複雜數組聲明

1 int *ptrs[10];//ptrs是含有10個整型指標的數組2 int (*p)[10];//p指向一個含有10個整型的數組3 int (&p)[10];//p引用一個含有10個整型的數組4 int *(&p)[10];//p是一個含有10個整型指標的數組的引用

五、數組操作

 1     unsigned a[11] = {}; 2     unsigned b; 3     while (cin >> b) 4     { 5         if(b<=100) 6         { 7             ++a[b/10]; 8         } 9         for(auto i : a)10       {11           cout<<i<<endl;12       }13     }
    string nums[] = {"one","two","three"};    string *p = &nums[0];    cout<<*p<<endl;//one    string *p2 = nums;    cout<<*p2<<endl;//one
1     string *pbeg = begin(nums);2     string *pend = end(nums);3     cout<<*pbeg<<" "<<*(--pend)<<endl;//one three

 

C++學習筆記(10)數組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.