Im trying to switch the values of 2 arrays, but the output is completely wrong.
Code:
#include <iostream>
using namespace std;
void test(int a[], int b[], int antal)
{
int c =0;
for (int i =0; i <= antal; i++)
{
c = a[i];
a[i] = b[i];
b[i] = c;
}
}
int main()
{
int a[1, 9, 8, 6], b[5, 5, 5, 5], antal =4;
for(int i =0; i < 4; i++)
cout << a[i];
cout << endl;
for(int i =0; i < 4; i++)
cout << b[i];
test (a, b, 4);
for(int i =0; i < 4; i++)
cout << a[i];
cout << endl;
for(int i =0; i < 4; i++)
cout << b[i];
return 0;
}
Can anyone help me see where the error lies?