Cpp Delete演算子 新しいページはコチラ
提供: yonewiki
(→delete演算子) |
(→delete演算子) |
||
| 17行: | 17行: | ||
delete pnReturnValue; | delete pnReturnValue; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | |||
| + | 例2 | ||
| + | <syntaxhighlight lang="cpp"> | ||
| + | int nLength =strlen(pcStrOrigin) | ||
| + | char *pcMessage; | ||
| + | pcMessage = new char[nLength]; | ||
| + | … | ||
| + | delete[] pcMessage; | ||
| + | </syntaxhighlight> | ||
| + | このように配列のメモリを解放できますが、メモリの大きさは配列終端が未使用あるいは\0あるいは0である必要があります。全部を使ってしまうと終端がわからず、メモリ解放処理が失敗します。 | ||