Arrays and Functions
Explore how to pass arrays to functions in C++ and modify their elements through function calls. Understand why arrays are passed by reference, and see practical examples that demonstrate traversing and updating array values inside functions.
We'll cover the following...
We'll cover the following...
Passing an array to a function
To pass an array to a function, we just have to specify the array type, followed by an array name and square brackets in the function parameters.
Example program
Let’s write a program that takes an array in its parameters.
In the program, we will traverse the array elements. If the value of an array element is less than 50, we will update the value at that index to -1.
Press the RUN button and see the output!
In the code above: ...