Jun 8, 2012 at 1:42am UTC
Hi I'm a real noob in c++ learning with an online tutorial and I can't find out how to give an array to a function, like
and my function addition is
int addition (int p_array[], int p_arraySize)
{
return p_array[0]+p_array[1];
}
int main()
{
int whatever, arraySize=2;
int array [arraySize);
array[0]=1;
array[1]=2;
whatever = addition(array[], arraySize);
return 0;
}
it says error: expected primary-expression before "]" token.
I'm sorry I have a bad english!! I guess this question has been answered somewhere else but I have many difficulties in english
Last edited on Jun 8, 2012 at 1:43am UTC
Jun 8, 2012 at 1:52am UTC
int array [arraySize); // should be ] instead of )
int addition (p_array[], int p_arraySize) // should be int p_array[]
whatever = addition(array[], arraySize); // should be array instead of array[]
Jun 8, 2012 at 2:04am UTC
Thanks alot tought it was whatever=addition(array[]....) was my error.