我必须在C ++中删除静态数组吗? [英] Must I delete a static array in C++?

查看:85
本文介绍了我必须在C ++中删除静态数组吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一些像这样的代码:

I am writing some code like this:

while(true) {
    int array[5];
    // do something
}

对于循环的每一圈,该数组都是一个新数组.我是否需要在循环结束时删除数组?

For each turn of the loop, the array is a new array. Do I need to delete the array at the end of the loop?

推荐答案

我是否需要在循环结束时删除数组?

Do I need to delete the array in the end of loop?

,您无需删除它,因为array具有自动存储时间.当退出每个while循环时,它将被释放.

No, you don't need to delete it because array has automatic storage duration. It will be released when goes out of each while loop.

您需要成对调用delete [] / new []delete / new.

这篇关于我必须在C ++中删除静态数组吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆