C ++静态数组与动态数组? [英] C++ Static array vs. Dynamic array?

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

问题描述

什么是一个静态数组,并在C动态数组之间的区别++?

What is the difference between a static array and a dynamic array in C++?

我要为我做一流的转让,它说不要使用静态数组,只有动态数组。我看过的书和网络,但我似乎不明白。

I have to do an assignment for my class and it says not to use static arrays, only dynamic arrays. I've looked in the book and online, but I don't seem to understand.

我想静在编译时被创建和动态运行时,但我可能内存分配被误以为这一点。

I thought static was created at compile time and dynamic at runtime, but I might be mistaking this with memory allocation.

您能解释一下在C ++中静态数组和动态数组之间的区别?

Can you explain the difference between static array and dynamic array in C++?

感谢。

推荐答案

本地阵列在栈上创建,并自动存储时间 - 你并不需要手动管理内存,但他们被摧毁的时候,他们的功能'再在两端。他们一定有一个固定大小:

Local arrays are created on the stack, and have automatic storage duration -- you don't need to manually manage memory, but they get destroyed when the function they're in ends. They necessarily have a fixed size:

int foo[10];

运营商新的[] 创建磁盘阵列具有动态存储时间和存储在堆(技术上的自由存储)。他们可以有任何尺寸,但你需要分配和释放自己,因为他们他们不是栈帧的一部分:

Arrays created with operator new[] have dynamic storage duration and are stored on the heap (technically the "free store"). They can have any size, but you need to allocate and free them yourself since they're not part of the stack frame:

int* foo = new int[10];
delete[] foo;

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

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