为int *阵列=新的INT [n];什么这个功能实际上是在做什么? [英] int *array = new int[n]; what is this function actually doing?

查看:285
本文介绍了为int *阵列=新的INT [n];什么这个功能实际上是在做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感到困惑如何创建动态定义数组:

I am confused about how to create a dynamic defined array:

 int *array = new int[n];

我不知道这是什么在做什么。我可以告诉它的创建是指向一个新的对象/ INT数组的指针指定数组?会有人照顾解释?

I have no idea what this is doing. I can tell it's creating a pointer named array that's pointing to a new object/array int? Would someone care to explain?

推荐答案

新的的分配给存储对象/数组,你要求的所需的内存量。在这种情况下,N为int的数字。

new allocates an amount of memory needed to store the object/array that you request. In this case n numbers of int.

指针然后将地址存储的内存块。

The pointer will then store the address to this block of memory.

但要注意,这种分配的内存块不会被释放写作,直到你告诉它让

But be careful, this allocated block of memory will not be freed until you tell it so by writing

delete [] array;

这篇关于为int *阵列=新的INT [n];什么这个功能实际上是在做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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