§ Arrays
can also be arguments of functions.
§
When an entire array is an argument of a
function, only the address of the array is passed and not the copy of the
complete array. Therefore, when a function is called with the name of the array
as the argument, address to the first element in the array is handed over to
the function.
Hence when array
is a function argument, only the address of the array is passed to the function
called. This implies that during its execution the function has the ability to
modify the contents of the array that is specified as the function argument. This
is an exception to the rule of passing the function arguments by value.
Function
declaration with array:
return_type function_name(data_type array_name[size]);
e.g.
float findaverage(int num, float list[10]);
NOTE: An array
name with an index number as a function argument will only pass that particular
array element’s value, like any other variables, to the function called.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.