I tried to increase a pointer size by creating another pointer and then copying it to the original pointer but firstly it only has prints the address of the memory stored in it and then it crashes with a debug assertion fail.
int sumArray(int* arr, unsigned r) {
r++;
int *secArr = new int[r];
for (int i = 0; i<r - 1; i++)
{
secArr[i] = arr[i];
}
secArr[r - 1] = sum % r;
delete[] arr;
arr = new int[r];
for (size_t i = 0; i < r - 1; i++)
{
arr[i] = secArr[i];
}
delete[] secArr;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire