I have a function in java
static int a2(int[] a)
{
int sumEven = 0;
int sumOdd = 0;
for (int i=0; i<a.length; i++)
{
if (a[i]%2 == 0)
sumEven += a[i];
else
sumOdd += a[i];
}
return sumOdd - sumEven;
}
I am calling it from main in java like
public static void main()
{
a2(new int[] {1});
a2(new int[] {1, 2});
a2(new int[] {1, 2, 3});
a2(new int[] {1, 2, 3, 4});
a2(new int[] {3, 3, 4, 4});
a2(new int[] {3, 2, 3, 4});
a2(new int[] {4, 1, 2, 3});
a2(new int[] {1, 1});
a2(new int[] {});
}
Where a2 is function and argument is array. This same thing I want to achieve in c++ but I can't pass array to function like I passed in java. It is giving error [error]taking address of temporary array.
In c++, I am doing like that
f((int[4]) {1,2,3,4});
Giving error => [error]taking address of temporary array.
How to achieve this?