[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppDeleteArray
Instead of using new[] and delete[], prefer a std::vector over an array by default (references 1 and 2).
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppDeleteArray
(C++) delete[]
Keyword related to delete. It frees the memory dynamically allocated to an array.int main() { const int arraySize = std::rand()%100; int * pArray = new int [arraySize]; std::cout << "Created an array size " << arraySize << std::endl; for (int i=0; i<arraySize; ++i) { pArray[i] = i*i; std::cout << i << " : "<< pArray[i] << std::endl; } delete[] pArray; return 0; }
- include <iostream>
Instead of using new[] and delete[], prefer a std::vector over an array by default (references 1 and 2).
Code links
- ::,scope operator
- <<,stream out operator
- #include
- cout
- endl
- #include
- iostream
- main
- return
- scope operator'::'
- std
- stream out operator '<<'
References
- 1) Bjarne Stroustrup. The C++ Programming Language (3rd edition).ISBN: 0-201-88954-4
- 2) Herb Sutter and Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
