I tried to build a function that takes an array and its size and returns an array with only the even numbers from the first array.
#include <iostream>
using namespace std;
int noOdds(int v[], int dim)
{
int vp[dim];
for (int i = 0, k = 0; i < dim; i++)
{
if (v[i] % 2 == 0)
{
vp[k] = v[i];
k++;
}
}
return vp;
}
int main()
{
int v1[3] = { 1,2,3 };
cout << noOdds(v1, 3);
return 0;
}
The error I am getting:
main.cpp: In function ‘int noOdds(int*, int)’:
main.cpp:21:12: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
21 | return vp;
| ^~
| |
| int*
I kept looking on the internet for different ways to solve this error, but I didn't find anything, I would be very grateful if someone could help me. Thank you!!