assume that we created dynamically allocated memory such as:
int SIZE = 10;
int *p = new int[SIZE];
for(int i = 0; i < SIZE; ++i)
p[i] = i;
Run Code Online (Sandbox Code Playgroud)
it will assing 0 to 9 to our pointer array.
Then i wanted to add 10,11,12 to the array
can i do :
p[10] = 10;
p[11] = 11;
p[12] = 12;
Run Code Online (Sandbox Code Playgroud)
or should i do:
delete[] p;
size = 13;
p = new int[SIZE];
for(int i = 0; i < …Run Code Online (Sandbox Code Playgroud)