-
Notifications
You must be signed in to change notification settings - Fork 1
/
newanddelete.cpp
53 lines (44 loc) · 1.11 KB
/
newanddelete.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// {"category": "C++11", "notes": "new and delete"}
#include <SDKDDKVer.h>
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <Windows.h>
using namespace std;
//------------------------------------------------------------------------------
//
// new and delete
//
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// Demo execution
//
//------------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
LPWSTR* strings = nullptr;
const auto count = MAXINT16;
try
{
strings = new LPWSTR[count](); // Zero initialized.
for (auto i = 0; i < count; i++)
{
strings[i] = new WCHAR[count];
_itow_s(i, strings[i], count, 10);
}
}
catch (bad_alloc)
{
cout << "Out of memory.\n";
}
if (strings != nullptr)
{
for (auto i = 0; i < count; i++)
{
delete[] strings[i];
}
}
delete[] strings;
return 0;
}