Passing array to function

In this tutorial you will learn about the Passing array to function and its application with practical example.

In this tutorial, you will learn passing array to function. You’ll learn to passing both one-dimensional and multidimensional arrays to a function. In C programming, several times we may require passing more than one values to a function parameter. With array we can pass multiple values to function parameter.

Suppose you have a function to sort the given parameters in ascending order. This would require you to pass all values as actual parameters to function. Here, instead of declaring n number of different variables and then passing them to function, we can have an array of required size and pass it to the function. This way we can pass any number of parameters to function using array. This will also resolve the complexity, since function will now work with any number of values. You can pass an array to a function in following two ways:

  1. call by value
  2. call by reference

Passing array to function in c by value

In this method, value of the actual parameter is copied into the function’s formal parameter. And these two types of parameters are stored in different memory locations.

Passing array to function in c by reference

In this method, actual and formal parameters refer to the same memory locations. Any change made into the actual parameter will reflect formal parameters.

In this tutorial we have learn about the Passing array to function and its application with practical example. I hope you will like this tutorial.