How do I call the C ++ function?

advertisements

I have a function with the prototype as

void test( int array [] , int b);

I know we can replce the protoype as: void test(int*, int);

In main() we declare the following arrays :

int array1[10], array2[10];

To set the body of the function to 0,

test ( array1 , b)
{
for ( int i = 0 ; i < b ; i++)
  array1[i] = 0;

}

can i do the follwing and why?

int main()
{// assuming b is the size of the array
test(array1 , b);
test(array2 , b) ;
return 0;
}

i know the basic of c++ im trying to write my own include files. I am just wondering if this is possible and is it a good choise?


You may be asking about the difference between formal parameters and actual parameters.

In your prototype

void test(int *array, size_t size);

the names 'array' and 'size' are the formal parameters. You use those names inside the body of your function.

In the code that invokes the function, you can use different names, which are the actual parameters.

so

int main()
{
   const size_t b = 10;
   int array1[10], array2[10];
   test(array1 , b);
   test(array2 , b) ;
   return 0;
}

Here array1 and b are the actual parameters to the first invocation and array2 and b are the actual parameters to the second invocation.

So yes, you can use whatever names you like as actual parameters, so long as the types of the variables match your prototype.