Passing Array to Function in C/CPP

If you are using C then use -

  1. return_type function(type arrayname[])
  2. return_type function(type arrayname[SIZE])
  3. return_type function(type *arrayname)

and For C++ use -

  1. void myFunction(int *param)
  2. void myFunction(int param[10])
  3. void myFunction(int param[])

Note: C++ does not allow to pass an entire array as an argument to a function. However, You can pass a pointer to an array by specifying the array's name without an index.

If you want to understand how you can use arry function in C/CPP read this article.

1 Like