C++ Programming Code Examples C++ > Beginners Lab Assignments Code Examples Passing arrays to a function Passing arrays to a function In this example, we are passing two arrays a & b to the function sum(). This function adds the corresponding elements of both the arrays and display them. #include <iostream> using namespace std; /* This function adds the corresponding elements of both the arrays and displays it. */ void sum(int arr1[], int arr2[]){ int temp[5]; for(int i=0; i<5; i++){ temp[i] = arr1[i]+arr2[i]; cout<<temp[i]<<endl; } } int main(){ int a[5] = {10, 20, 30, 40 ,50}; int b[5] = {1, 2, 3, 4, 5}; //Passing arrays to function sum(a, b); return 0; }