How to completely remove one element of an array?

Let's say I have an array:
 
int ARRAY[] = [3,1,4,1,5,9];


Now lets pretend I want to get rid of an element completely, say number 2, leaving me with

[3,1,1,5,9]

How would I do this, generally speaking, for any element of an array?

EDIT:
I just had an idea:
I could rotate the array about element number 2 to get

[3,1,1,5,9,4]

and then (somehow?) delete the last element... if that's possible...
Last edited on
You should use braces instead of square brackets: int ARRAY[] = {3,1,4,1,5,9};.

The size of an array is fixed and cannot be changed. You can imitate this if you allocate the memory on the heap, create another array of an appropriate size and copy the necessary information, then call delete on the original one.

If you want more convenient ways to insert/remove data, condsider using a std::vector.
If you want more convenient ways to insert/remove data, condsider using a std::vector.
a std::vector is much like a dynamic array for insertion/removal of elements a std::list is better
http://www.cplusplus.com/reference/stl/list/
Topic archived. No new replies allowed.