I'm learning c ++ And the syntax of putting a std :: array into the function confuses me.

#include <iostream>
#include <array>

using namespace std;

void printArray(const std::array<int, 5> &n)
{
    std::cout << "length: " << n.size() << endl;

    for (int j = 0; j < n.size(); j++ )
    {
        cout << "n[" << j << "] = " << n[j] << endl;
    }

}

int main()
{

    array<int, 5> n = {1,2,3,4,5};

    printArray(n);

    return 0;
}
  1. I want to ask about 'const', what role does it play and what effect does it have if not using it?

  2. Why do we have to use &n while the name of an array is already pointer

0 Answers