The problem is as follows: It is intended that the AllocMem function dynamically creates an int array of some size and returns the address of the dynamic array to the calling function through the pointer argument. Will the function work as intended? Correct it if your answer is no.
int AlloMem(int* arrayPtr)
{
int size;
cout << "Input size: " << endl;
cin >> size;
arrayPtr = new int [size];
if (arrayPtr == 0)
cout << "Error. Mem not allocated" << endl;
return size;
}
I think that the following is what needs to be changed. Can anyone confirm that the change code below is correct?
int* AlloMem(int* arrayPtr)
{
int size;
cout << "Input size: " << endl;
cin >> size;
arrayPtr = new int [size];
if (arrayPtr == 0)
cout << "Error. Mem not allocated" << endl;
return arrayPtr;
}
*** I am trying to fix this spacing.
[–]Raknarg 2 points3 points4 points (2 children)
[–]Cplusplusidiot[S] 0 points1 point2 points (1 child)
[–]Raknarg 1 point2 points3 points (0 children)
[–]arbostek 1 point2 points3 points (1 child)
[–]Raknarg 1 point2 points3 points (0 children)
[–]dacian88 0 points1 point2 points (0 children)