Wednesday 13 February 2013

Passing Arrays to Functions in C Programming



Arrays are inherently passed to functions by the call by reference method. for instance, if an array called num_array of size 10 is to be passed to a function called stringfunc(), then it would be passed as follows:

stringfunc (num_array);

Recall that num_array is actually the address of the first element of the array. So, this would be a call by reference. The parameter of the called function, say, number_list could be declared in any of the following ways:

stringfunc(number_list)
int number_list[];
{
--
--

]

OR

stringfunc (number_list)
int number_list[10];
{
--
--
}

OR

stringfunc (number_list)
int *number_list;
{
--
--
}

0 comments:

Post a Comment

Powered by Blogger.