Since the number of elements is determined by some conditions, I wrote a program like this;
int i = 0; int *layer; while (i != 12){ layer = new int; layer[i] = i; cout << layer[i] << endl; i++; } delete[] layer; return 0; I get the result; 0 1 2 3 4 5 6 And then program crashes. What is the reason of this and how should I modify the program in order to allocate memory for unknown number of elements? Thanks in advance!