Need a project done?

C++ Programming Developer

Search This Blog

Pass array in a function in C++


/*
Write a program to initialize value into 1-D array. Pass the array as argument to a function and
compute the sum of array. The function should return the calculate sum to the calling function.
*/


#include <iostream>
using namespace std;



inline int sum(int One_d[], int size);

int main()
{
int One_d[] = {4,2,1};
cout<<"SUM: " << sum(One_d,3) << endl;

return 0;
}

inline int sum(int One_d[], int size)
{
return  One_d[0] + One_d[1] + One_d[2];
}
"Don't let anyone ever make you feel like you don't deserve what you want."