1. Write user defined function arrayFunction() in C++ which will initialize array by taking values from user at run time and then call this function in main function which will return this array from the calling function to the called function (to the main function) and then show all items of this array in main function using loop.
#include<iostream>
using namespace std;
int* arrayFunction(int n)
{
int* arr=new int[n];
cout<<"Enter the elements of array : ";
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
return arr;
}
int main()
{
int n;
cout<<"Enter number of elements in the array ";
cin>>n;
int* ar=arrayFunction(n);
cout<<"\nElements of array are : ";
for(int i=0;i<n;i++)
{
cout<<ar[i]<<" ";
}
delete[] ar;
}
Comments
Leave a comment