美文网首页
数组形参传递

数组形参传递

作者: 尾蝉 | 来源:发表于2017-08-22 15:13 被阅读0次
    #include<iostream>
    #include<string>
    #include<vector>
    using namespace std;
    void print(const int *beg, const int *end)
    {
        while (beg != end)
            cout << *beg++ << endl;
    }
    void print2(const int ia[], size_t size)
    {
        for (size_t i = 0; i != size; ++i) {
            cout << ia[i] << endl;
        }
    }
    void print3(int(&arr)[10])
    {
        for (auto elem : arr)
            cout << elem << endl;
    }
    
    int main()
    {
        int j[5] = { 0,1,2,3,4 };
        print(begin(j),end(j));
        int i[2] = { 0,1 };
        print2(i, end(i) - begin(i));
        int k[10] = { 0,1,2,3,4,5,6,7,8,9 };
        print3(k);
    
    
        system("pause");
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:数组形参传递

          本文链接:https://www.haomeiwen.com/subject/jcjldxtx.html