Thursday, July 30, 2009

How to delete all the elemnts in an array in c++?

need it now.. plzzz reply..........

How to delete all the elemnts in an array in c++?
Repeat to yourself as many times as it takes, that an array is a pointer..an array is a pointer..





Arkangyl presents a method to create/delete a dynamically created array - that may or may not be what you want to do. Your question isn't clear enough.





Say your array is defined and declared in your code:


Foo foo_array[10]


This array is static, and you cannot change its size at runtime.





If these aren't answering your question, you may not be asking in your question what you think you are.
Reply:Unless you've designed some new data type, an array IS a pointer. If you allocated an array of objects using 'new', you can deallocate them as follows:





Foo *foo_array;





foo_array = new Foo[10]; // the allocation


delete[] foo_array; // the deallocation





If you can give more details regarding the situation, I could give a better answer.


No comments:

Post a Comment