1 | initial version |
In C Programming, an array can be passed as an argument to a function by specifying the array name without square brackets, along with its size (if known), in the function parameter list. The following is an example of this:
void myFunction(int arr[], int size) {
// function code
}
In this example, the myFunction
function takes an array of integers arr
and its size size
as arguments. Within the function, the elements of the array can be accessed using array indexing (arr[0]
, arr[1]
, etc.).
When calling the function, the array name is also passed without square brackets. For example:
int main() {
int myArray[5] = {1, 2, 3, 4, 5};
myFunction(myArray, 5);
return 0;
}
In this example, the myArray
array is passed to myFunction
, along with its size (5
).