Simplified version of my code looks like:
int * tab = nullptr;
int index = 0;
int size = 1; // Program works unless this is init'd to something higher!
int a = 0;
while (true)
{
int input;
std::cin >> input;
if (input == 0) break;
index++;
if (index >= size) {
size = size * 2;
int * newt = new int[size];
for (int i = 0; i < a; ++i)
newt[i] = tab[i];
delete[] tab;
tab = newt;
}
tab[a] = input;
a++;
}
Whenever I try to change 'size' integer to be bigger than 1, the program crushes. Visual Studio shouts about memory accessibility problem, but still I can't figure what's exactly wrong. I don't have to change it, but I've struggled with this code for more than hour untill I accidently changed variable to be 1 and then it worked. I'm just curious why.