I know that arrays can be created on the stack with syntax such as int array[5];
where the size must be known at compile time and array
is a non modifiable l-value.
You can also create an array dynamically on the heap with new
such as int* array = new int[5];
where it becomes possible to have a size of variable length and resize the array.
But what about something like:
int* array;
array[2] = 3;
cout << array[2] << endl;
Which creates an array on the stack that appears to be resizable because I can continue adding elements. The only other thing that should be kept track of is the size.
I wrote the above code accidentally in a project and I haven't seen it used ever. I not sure if it should be used at all, but I'm also not sure what's incorrect about it.