char a [6]和char * p = new char [6]之间的区别? [英] The difference between char a[6] and char *p=new char[6] ?

查看:98
本文介绍了char a [6]和char * p = new char [6]之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部


我想知道char a [6]和char * p = new

char [6]之间的区别堆和堆栈之间的区别,如果

char a [6]对应于MEMORY中的堆栈,并且char * p = new

char [6]对应于MEMORY的堆。


给我一些提示。

谢谢。

解决方案

在文章< 87 ************************** @ posting.google.com> ;,
ww*******@mail2.swjtu.edu.cn (wwj)写道:

全部

我想知道char a [6]和char * p = new
char [6]之间的区别堆栈和堆栈之间的区别,如果
char a [6]对应于MEMORY中的堆栈,并且char * p = new
char [6]对应堆栈记忆。




你能非常仔细地看看这个名字吗?您要发布的新闻组是什么?b $ b该新闻组的名称是comp.lang.c ++吗?如果没有,

然后你将你的C ++问题发布到错误的新闻组。


wwj写道:

你好,所有

我想知道char a [6]和char * p = new
char [6]


之间的区别是第二个声明在C中没有任何意义。

C ++是大厅里的第二组,在左边......

和堆之间的区别堆栈,


这与C语言无关。

如果
char a [6]对应堆栈在MEMORY中,char * p = new
char [6]对应于MEMORY的堆。


由于C语言没有堆栈或堆的概念,并且由于

秒语句在C中没有意义,我们无法回答一个问题。

给我一些提示。


第一个提示:C和C ++是两种不同的语言。请在

相应的新闻组上发帖。


第二提示:

#include< regulars_please_correct_me_if_necessary.h>


C< ot>和C ++< / ot>有自动内存的概念和动态内存的概念。


自动内存是默认存储,本地变量通常是

自动。这意味着在块的开头会自动为这些

变量分配内存,并且在块结束时自动释放该内存。
。 >

自动内存*可以*在*某些*平台上,用堆栈实现。


动态内存是按需分配的内存,一个特殊的

机制(在C中,通常是''malloc()''函数,< ot>在C ++中通常是

''new''运算符< / ot>),并且必须通过代码释放 - 通常在C中使用

''free()''函数< ot>并在C ++中使用''delete''< / ot> )。没有释放

动态分配的内存(通常)会导致内存泄漏。


动态内存*可能*在*某些*平台上,用堆实现。


第三个提示:请学习C和C ++之间的区别,选择你喜欢的

,给自己一个*好*预订,并在

适当的小组上发布 - 在您阅读了小组的常见问题解答后。

谢谢。



请不要尖叫,它伤害了我的耳朵。


布鲁诺


< blockquote> ...... ~~

Christian Bau< ch *********** @ cbau.freeserve.co.uk>在消息新闻中写道:< ch ********************************* @ slb-newsm1.svr.pol。 co.uk> ...

在文章< 87 ************************** @ posting.google.google .com>,
ww*******@mail2.swjtu.edu.cn (wwj)写道:

所有

我想知道char a [6]和char * p = new之间的区别
char [6]以及堆和堆栈之间的区别,如果
char a [6]对应于MEMORY中的堆栈,并且char * p = new
char [ 6]对应于MEMORY的堆。



您是否可以非常仔细地查看您要发布的新闻组的名称?该新闻组的名称是comp.lang.c ++吗?如果没有,那么你将C ++问题发布到错误的新闻组。



Hi ,all

I want to know the difference between char a[6] and char *p=new
char[6] and the difference between the heap and the stack ,and if the
char a[6] is corresponding to the stack in MEMORY,and char *p=new
char[6] is corresponding to the heap of MEMORY.

Give me some hint.
THANK YOU.

解决方案

In article <87**************************@posting.google.com >,
ww*******@mail2.swjtu.edu.cn (wwj) wrote:

Hi ,all

I want to know the difference between char a[6] and char *p=new
char[6] and the difference between the heap and the stack ,and if the
char a[6] is corresponding to the stack in MEMORY,and char *p=new
char[6] is corresponding to the heap of MEMORY.



Could you have a very very close look at the name of the newsgroup you
are posting to? Is the name of that newsgroup "comp.lang.c++"? If not,
then you are posting your C++ questions to the wrong newsgroup.


wwj wrote:

Hi ,all

I want to know the difference between char a[6] and char *p=new
char[6]
The difference is that the second statement has no meaning in C.
C++ is the second group down the hall, on the the left...
and the difference between the heap and the stack,
This has nothing to do with the C language.
and if the
char a[6] is corresponding to the stack in MEMORY,and char *p=new
char[6] is corresponding to the heap of MEMORY.
Since the C language has no notion of stack or heap, and since the
second statement has no meaning in C, we can''t answer such a question.
Give me some hint.
first hint : C and C++ are two different languages. please post on the
appropriate newsgroup.

second hint :

#include <regulars_please_correct_me_if_necessary.h>

C <ot>and C++</ot> have a notion of automatic memory and a notion of
dynamic memory.

Automatic memory is the default storage, and local variables are usually
automatic. This means that memory is automatically allocated for these
variable at the beginning of the block, and that this memory is
automatically freed at the end of the block.

Automatic memory *may* be, on *some* platforms, implemented with a stack.

Dynamic memory is memory that is allocated on demand, with a special
mechanism (in C, usually the ''malloc()'' function, <ot>in C++ usually the
''new'' operator</ot>), and that must be freed by code - usually in C with
the ''free()'' function <ot>and in C++ with ''delete''</ot>). Not freeing
dynamically allocated memory (usually) causes a ''memory leak''.

Dynamic memory *may* be, on *some* platforms, implemented with a ''heap''.

Third hint : please learn the difference between C and C++, choose the
one you like, get yourself a *good* book on it, and post on the
appropriate group - after you''ve read the group''s FAQ.
THANK YOU.


Please dont scream, it''s hurting my ears.

Bruno


......~~
Christian Bau <ch***********@cbau.freeserve.co.uk> wrote in message news:<ch*********************************@slb-newsm1.svr.pol.co.uk>...

In article <87**************************@posting.google.com >,
ww*******@mail2.swjtu.edu.cn (wwj) wrote:

Hi ,all

I want to know the difference between char a[6] and char *p=new
char[6] and the difference between the heap and the stack ,and if the
char a[6] is corresponding to the stack in MEMORY,and char *p=new
char[6] is corresponding to the heap of MEMORY.



Could you have a very very close look at the name of the newsgroup you
are posting to? Is the name of that newsgroup "comp.lang.c++"? If not,
then you are posting your C++ questions to the wrong newsgroup.



这篇关于char a [6]和char * p = new char [6]之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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