In C++ Create a method that populates an array: pArray(), be sure to have the appropriate return type, and parameters. Call pArray() in your main() method.
#include <iostream> using namespace std; int* pArray(int size){ int* arr = new int[size]; for(int i = 0;i<size;i++){ cout<<"Enter value: "; cin>>arr[i]; } return arr; } int main() { int* arr = pArray(5); cout<<"Array:"<<endl; for(int i = 0;i<5;i++){ cout<<arr[i]<<" "; } cout<<endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.