Creating an Array: Difference between revisions

Line 222:
=={{header|C++}}==
Using dynamically-allocated (i.e. [[Heap]]) memory:
(Warning, deprecated and not safe)
<lang cpp> const int n = 10;
try {
int* myArray = new int[n];
if( int* myArray != NULL)new int[n];
{
myArray[0] = 1;
myArray[1] = 2;
delete[] myArray;
myArray = NULL;
} catch (std::bad_alloc a) {
std::cerr << "allocation failed" << std::endl;
}</lang>
 
Anonymous user