passinng array by reference problem?

i want to pass an array by reference from the main and then use the array again in the main function:


void reverseit(int[])
void main()
{
int array1[4]={1,2,3,4}
reverseit(array1); //i want that the result of the
cout<<"Reverse array is:"<<endl<<array1); function call should be displayed
in the cout follwing the call.//
}

what should be the function definition to reverse the array and cout it in the main.
thanx.
I'm not sure I understood you correctly, but you may try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

template <std::size_t N>
void display_reversed(int (&array)[N])
{
   for (int * it = array + N - 1; it >= array; --it)
      std::cout << *it << std::endl;
}

int main()
{
   int array1[4] = {1,2,3,4};

   std::cout << "Reverse array is:" << std::endl;

   display_reversed(array1);

   return 0;
}

Output:

Reverse array is:
4
3
2
1
Arrays are always passed by reference
Topic archived. No new replies allowed.