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

查看:74
本文介绍了我必须在 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天全站免登陆