You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -26,9 +24,9 @@ CDialog* MyDialog = new CDialog;
26
24
delete MyDialog;
27
25
```
28
26
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).
30
28
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`:
32
30
33
31
```cpp
34
32
int* set = newint[100];
@@ -40,11 +38,11 @@ Using the **delete** operator on an object deallocates its memory. A program tha
40
38
41
39
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).
42
40
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.
44
42
45
43
## Using delete
46
44
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:
48
46
49
47
```cpp
50
48
// expre_Using_delete.cpp
@@ -70,7 +68,7 @@ int main()
70
68
}
71
69
```
72
70
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.
0 commit comments