I am doing a little bit practice of the pointers and I am facing this error? Anybody knows why is it there?
#include <iostream>
using namespace std;
bool expandarray(int **arr, int oldsize, int newsize)
{
if(oldsize > newsize)
return false;
int *newarray = new int[newsize];
for(int i = 0; i < newsize; i++)
{
newarray[i] = 0;
}
for(int i = 0; i < oldsize; i++)
{
newarray[i] = *arr[i];
}
delete [](*arr);
*arr = newarray;
return true;
}
int main()
{
int * array = new int[5];
for(int i = 0; i < 5; i++)
{
array[i] = i+6;
//cout << array[i] << " ";
}
expandarray(&array,5,7);
system("pause");
}
It is not getting the elements of the arr. The error occurs at newarray[i] = *(arr[i]);