pass array in function in c++ by R4R Team

How we pass array in function that declared in class in C++ ?

program:

#include < iostream>
using namespace std;
class r4r
{
public:
//class method or function
int function(int *arr)
{
int i;
cout<<"Array is:"<< endl;
for(i=0;i< 5;i++)
{
cout<< arr[i]<<" ";
}
}
};
int main()
{
int a[5],i;
r4r obj;
cout<<"Enter 5 number in array"<< endl;
for(i=0;i< 5;i++){
cin>>a[i];
}
//pass in function
obj.function(a);
return 0;
}


output-

Enter 5 number in array
3 2 6 1 0
Array is:
3 2 6 1 0




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!