Array:
Array is the collection of different values having same data type.
-We have a integer Array that having all integer values.
-Character array is known as String.
What we do here?
Example-
Array is {1,2,3,4,5}
Add 2 in Array then {3,4,5,6,7}
program:
#include < iostream>
using namespace std;
class r4r
{
public:
//class method or function
int function(int *arr,int n)
{
int i;
cout<<"Array after number add is:"<< endl;
for(i=0;i< 5;i++)
{
cout<< arr[i]+n<<" ";
}
}
};
int main()
{
int a[5],i,n;
r4r obj;
cout<<"Enter 5 number in array"<< endl;
for(i=0;i< 5;i++){
cin>>a[i];
}
cout<<"Enter number to add in array"<< endl;
cin>>n;
//pass in function
obj.function(a,n);
return 0;
}
Enter 5 number in array
1 2 3 4 5
Enter number to add in array
2
Array after number add is:
3 4 5 6 7