数组形参传递

#include
#include
#include
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;
}

你可能感兴趣的:(数组形参传递)