+ 12

Hi people, how can i flush or delete the cells of an array of ints in c++?

28th Apr 2017, 7:52 PM
Umbe
Umbe - avatar
5 Respuestas
+ 11
OK but i' m sorry I said that badly. i was wondering how to delete the memory in the cells , not necessarily the cells themselves
28th Apr 2017, 8:47 PM
Umbe
Umbe - avatar
+ 10
mmm.. OK thenks i will try all
28th Apr 2017, 11:20 PM
Umbe
Umbe - avatar
+ 5
Umbe, can you give some more details on the code? how was the array allocated? int arr[SIZE]; or int *arr = new int[SIZE];
28th Apr 2017, 8:07 PM
Burey
Burey - avatar
+ 5
You can't delete array cells int arr[] = {1,2,3,4} for example has a fixed size of 4, you can't make it smaller or bigger. In order to support deletion ( and adding ) you have to look for dynamic arrays ( int * arr = new int[size]) But since this is quite hard to manage correctly C++ provides you with wrappers to manage this for you vectors are what you're looking for which support adding and deletion. http://www.cplusplus.com/reference/vector/vector/
28th Apr 2017, 8:10 PM
Dennis
Dennis - avatar
+ 5
If you have the array allocated by new you can simply call delete[] arr;
28th Apr 2017, 9:45 PM
Dennis
Dennis - avatar