Skip to content

Commit 1c53da6

Browse files
author
Colin Robertson
committed
Address DD964713 about /sdl effects
1 parent 83ba816 commit 1c53da6

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

docs/cpp/delete-operator-cpp.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "delete Operator (C++)"
3-
ms.date: "11/04/2016"
3+
ms.date: "08/12/2019"
44
f1_keywords: ["delete_cpp"]
55
helpviewer_keywords: ["delete keyword [C++], syntax", "delete keyword [C++], deallocating objects", "delete keyword [C++]"]
66
ms.assetid: de39c900-3f57-489c-9598-dcb73c4b3930
@@ -11,10 +11,8 @@ Deallocates a block of memory.
1111

1212
## Syntax
1313

14-
```
15-
[::] delete cast-expression
16-
[::] delete [ ] cast-expression
17-
```
14+
> [`::`] `delete` *cast-expression*
15+
> [`::`] `delete []` *cast-expression*
1816
1917
## Remarks
2018

@@ -26,9 +24,9 @@ CDialog* MyDialog = new CDialog;
2624
delete MyDialog;
2725
```
2826

29-
Using **delete** on a pointer to an object not allocated with **new** gives unpredictable results. You can, however, use **delete** on a pointer with the value 0. This provision means that, when **new** returns 0 on failure, deleting the result of a failed **new** operation is harmless. See [The new and delete Operators](../cpp/new-and-delete-operators.md) for more information.
27+
Using **delete** on a pointer to an object not allocated with **new** gives unpredictable results. You can, however, use **delete** on a pointer with the value 0. This provision means that, when **new** returns 0 on failure, deleting the result of a failed **new** operation is harmless. For more information, see [The new and delete Operators](../cpp/new-and-delete-operators.md).
3028

31-
The **new** and **delete** operators can also be used for built-in types, including arrays. If `pointer` refers to an array, place empty brackets before `pointer`:
29+
The **new** and **delete** operators can also be used for built-in types, including arrays. If `pointer` refers to an array, place empty brackets (`[]`) before `pointer`:
3230

3331
```cpp
3432
int* set = new int[100];
@@ -40,11 +38,11 @@ Using the **delete** operator on an object deallocates its memory. A program tha
4038

4139
When **delete** is used to deallocate memory for a C++ class object, the object's destructor is called before the object's memory is deallocated (if the object has a destructor).
4240

43-
If the operand to the **delete** operator is a modifiable l-value, its value is undefined after the object is deleted.
41+
If the operand to the **delete** operator is a modifiable l-value, its value is undefined after the object is deleted. If the [/sdl (Enable additional security checks)](/cpp/build/reference/sdl-enable-additional-security-checks) compiler option is specified, the operand to the **delete** operator is set to an invalid value after the object is deleted.
4442

4543
## Using delete
4644

47-
There are two syntactic variants for the [delete operator](../cpp/delete-operator-cpp.md): one for single objects and the other for arrays of objects. The following code fragment shows how these differ:
45+
There are two syntactic variants for the [delete operator](../cpp/delete-operator-cpp.md): one for single objects and the other for arrays of objects. The following code fragment shows how they differ:
4846

4947
```cpp
5048
// expre_Using_delete.cpp
@@ -70,7 +68,7 @@ int main()
7068
}
7169
```
7270

73-
The following two cases produce undefined results: using the array form of delete (delete [ ]) on an object and using the nonarray form of delete on an array.
71+
The following two cases produce undefined results: using the array form of delete (`delete []`) on an object, and using the nonarray form of delete on an array.
7472

7573
## Example
7674

0 commit comments

Comments
 (0)