Answer to Question #191174 in C++ for python

Question #191174

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.


1
Expert's answer
2021-05-13T13:53:19-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment