473,396 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

The difference between char a[6] and char *p=new char[6] ?

wwj
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.
Nov 13 '05 #1
24 3592
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.
Nov 13 '05 #2
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

Nov 13 '05 #3
wwj
......~~
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.

Nov 13 '05 #4
wwj
Bruno ,Anyway firstly I thank you ,it's my wrong to post it here and
now yet I can not tell from c and c++ well. Then,I want to say that
our world is developing ,all developing,and the language c not be
invent from uk or by you or Christian Bau,ple you do not regulate(this
word not proper) it or sneer at others (new one) or rave at others .
Bruno Desthuilliers <bd***********@removeme.free.fr> wrote in message news:<3f***********************@news.free.fr>...
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

Nov 13 '05 #5
wwj <ww*******@mail2.swjtu.edu.cn> scribbled the following:
Bruno ,Anyway firstly I thank you ,it's my wrong to post it here and
now yet I can not tell from c and c++ well. Then,I want to say that
our world is developing ,all developing,and the language c not be
invent from uk or by you or Christian Bau,ple you do not regulate(this
word not proper) it or sneer at others (new one) or rave at others .


In other words, because neither Bruno or Christian invented C, this
newsgroup can freely be abused by posting off-topic messages which don't
concern C at all?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"You could take his life and..."
- Mirja Tolsa
Nov 13 '05 #6
wwj wrote:

Bruno ,Anyway firstly I thank you ,it's my wrong to post it here and
now yet I can not tell from c and c++ well. Then,I want to say that
our world is developing ,all developing,and the language c not be
invent from uk or by you or Christian Bau,ple you do not regulate(this
word not proper) it or sneer at others (new one) or rave at others .

Don't top-post. Your replies belong following properly trimmed quotes.
This newsgroup has topicality guidelines, which will be enforced by all
the regulars. Those two happened to be the first to correct you, others
would certainly have if they hadn't.

I suggest you apologize to the group and the two individuals for your
poor behavior.


Brian Rodenborn
Nov 13 '05 #7
Joona I Palaste wrote:
wwj <ww*******@mail2.swjtu.edu.cn> scribbled the following:
Bruno ,Anyway firstly I thank you ,it's my wrong to post it here and
now yet I can not tell from c and c++ well. Then,I want to say that
our world is developing ,all developing,and the language c not be
invent from uk or by you or Christian Bau,ple you do not regulate(this
word not proper) it or sneer at others (new one) or rave at others .


In other words, because neither Bruno or Christian invented C, this
newsgroup can freely be abused by posting off-topic messages which don't
concern C at all?


wwj obviously has a language barrier, and is doing his/her best.
So there is no need to pick at him. Simply drop it, and see what
develops. He already explained he doesn't know the difference
between C and C++, and obviously has not been told to lurk before
posting.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #8
wwj
i have said its my wrong to post it here !!!!!!!
Joona I Palaste <pa*****@cc.helsinki.fi> wrote in message
In other words, because neither Bruno or Christian invented C, this
newsgroup can freely be abused by posting off-topic messages which don't
concern C at all?

Nov 13 '05 #9
wwj
why?why apologize for my poor behavior ?what is my poor behavior?
Default User <fi********@boeing.com.invalid> wrote in message news:<3F***************@boeing.com.invalid>...
Don't top-post. Your replies belong following properly trimmed quotes.
This newsgroup has topicality guidelines, which will be enforced by all
the regulars. Those two happened to be the first to correct you, others
would certainly have if they hadn't.

I suggest you apologize to the group and the two individuals for your
poor behavior.


Brian Rodenborn

Nov 13 '05 #10
Don't mind them, see some of the other threads:

Asking if elements in struct arre zero
"Mastering C Pointers"....
Interview question !!!
ANSI C compliance

for a discussion of why you got jumped on so harshly. It is unfortunate
that people are so rude to someone just seeking an answer to a simple
question. One (non-sarcastic) post pointing out that it's off-topic is
quite enough. No need for a pathetic display of severe personality defects.

But yes your post has to do with C++, so unfortunately you won't get a good
answer here. But let me try, to make up for the harsh treatment (flames be
gone, it's off-topic anyway):

char a[6], if declared in a function, is a character array on the stack,
typically (flamers note: if I go into auto, it's going to take a lot more
explanation than he cares to hear, so STFU)

char *p = new char[6]; assigns to p a pointer to the beginning of 6
bytes of dynamically allocated memory, typically located on the "heap" as
you said

Google for "stack" and some other stuff maybe "function" "compiler", if you
don't know what a stack is. It's an abstract data type, and can be used to
implement variables declared in a function in C. That is, it manages their
automatic cleanup after the function exits. In contrast, you must
explicitly call "delete p" in order to free the memory allocated by new --
otherwise you have a memory leak.

The difference is that they are basically different systems of managing
memory. With a stack, you don't have to worry about cleaning up -- however
the variable has limited scope. A variable on the heap persists as long as
you need it, and you take responsibility for cleaning it up yourself.

Roose

"wwj" <ww*******@mail2.swjtu.edu.cn> wrote in message
news:87**************************@posting.google.c om...
why?why apologize for my poor behavior ?what is my poor behavior?
Default User <fi********@boeing.com.invalid> wrote in message

news:<3F***************@boeing.com.invalid>...
Don't top-post. Your replies belong following properly trimmed quotes.
This newsgroup has topicality guidelines, which will be enforced by all
the regulars. Those two happened to be the first to correct you, others
would certainly have if they hadn't.

I suggest you apologize to the group and the two individuals for your
poor behavior.


Brian Rodenborn

Nov 13 '05 #11
Roose wrote:

<snip>
But yes your post has to do with C++, so unfortunately you won't get a
good
answer here.
He will, however, get a good answer in comp.lang.c++
But let me try, to make up for the harsh treatment (flames
be gone, it's off-topic anyway):
Not only will he get a good answer in comp.lang.c++ but, also, any mistakes
in that answer will stand a much better chance of correction if it is
presented in the correct newsgroup.


char a[6], if declared in a function, is a character array on the
stack,
That is not necessarily true.
char *p = new char[6]; assigns to p a pointer to the beginning of 6
bytes of dynamically allocated memory, typically located on the "heap" as
you said


No, it's a syntax error in C, which is the topic of this newsgroup.

<snip>

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #12
wwj
Ok,thanks Roose very much.You are a good person , goodness.

In our here ,I learn from school that basiclly C++ is a extension of
C,and C is a subset of C++,expcept some difference.Maybe it is that my
teacher do not express that clearly or I do not understand that
clearly.So sorry for everyone ,I wish this post ends the heartrending
topic,and all not waster time on the confused quarrel.
"Roose" <no****@nospam.nospam> wrote in message news:<rH*****************@newssvr14.news.prodigy.c om>...
Don't mind them, see some of the other threads:

Asking if elements in struct arre zero
"Mastering C Pointers"....
Interview question !!!
ANSI C compliance

for a discussion of why you got jumped on so harshly. It is unfortunate
that people are so rude to someone just seeking an answer to a simple
question. One (non-sarcastic) post pointing out that it's off-topic is
quite enough. No need for a pathetic display of severe personality defects.

But yes your post has to do with C++, so unfortunately you won't get a good
answer here. But let me try, to make up for the harsh treatment (flames be
gone, it's off-topic anyway):

char a[6], if declared in a function, is a character array on the stack,
typically (flamers note: if I go into auto, it's going to take a lot more
explanation than he cares to hear, so STFU)

char *p = new char[6]; assigns to p a pointer to the beginning of 6
bytes of dynamically allocated memory, typically located on the "heap" as
you said

Google for "stack" and some other stuff maybe "function" "compiler", if you
don't know what a stack is. It's an abstract data type, and can be used to
implement variables declared in a function in C. That is, it manages their
automatic cleanup after the function exits. In contrast, you must
explicitly call "delete p" in order to free the memory allocated by new --
otherwise you have a memory leak.

The difference is that they are basically different systems of managing
memory. With a stack, you don't have to worry about cleaning up -- however
the variable has limited scope. A variable on the heap persists as long as
you need it, and you take responsibility for cleaning it up yourself.

Roose

"wwj" <ww*******@mail2.swjtu.edu.cn> wrote in message
news:87**************************@posting.google.c om...
why?why apologize for my poor behavior ?what is my poor behavior?
Default User <fi********@boeing.com.invalid> wrote in message

news:<3F***************@boeing.com.invalid>...
Don't top-post. Your replies belong following properly trimmed quotes.
This newsgroup has topicality guidelines, which will be enforced by all
the regulars. Those two happened to be the first to correct you, others
would certainly have if they hadn't.

I suggest you apologize to the group and the two individuals for your
poor behavior.


Brian Rodenborn

Nov 13 '05 #13
ww*******@mail2.swjtu.edu.cn (wwj) wrote:

[ Don't top-post, please. Corrected. ]
"Roose" <no****@nospam.nospam> wrote in message news:<rH*****************@newssvr14.news.prodigy.c om>...
char a[6], if declared in a function, is a character array on the stack,
typically (flamers note: if I go into auto, it's going to take a lot more
explanation than he cares to hear, so STFU)
The point is that "automatic memory" is a higher-level concept, and
therefore more useful to the reliable, foresightful programmer than "on
the stack". In particular, automatic memory has properties that a stack
need not have, and vice versa.
Besides, automatic memory need not be kept in any stack. It's quite
common, for example, for the smaller auto objects to reside in
registers. Well-written C doesn't care about the difference, as long as
auto objects function as the Standard says they should.
char *p = new char[6]; assigns to p a pointer to the beginning of 6
bytes of dynamically allocated memory, typically located on the "heap" as
you said

Google for "stack" and some other stuff maybe "function" "compiler", if you
don't know what a stack is. It's an abstract data type,
Not in this context, it isn't. _If_ automatic memory is placed in a
stack, it's almost certainly a hardware one. Of course, it would be
possible to write a C implementation for a LISP machine which puts its
auto memory in a software stack, which would be an example of an ADT
after all... and a well-written C program wouldn't care a jot about his
detail.
That is, it manages their automatic cleanup after the function exits.
Erm, no. The demands of automatic memory do that. That's why it's called
"automatic", see? Internally, the C implementation does a lot of byte
shuffling whether your auto memory is on a stack or not; but the point
is that this is hidden from you no matter how it is implemented.
The difference is that they are basically different systems of managing
memory. With a stack, you don't have to worry about cleaning up -- however
the variable has limited scope.

YM duration. Memory has no scope, identifiers have scope. It _is_
possible to have allocated memory, with only one identifier pointing to
it which has block scope, but with allocated duration which lasts beyond
that scope - and this knowledge is important, because failure to
recognise it often causes memory leaks. Like this:

{
int *a;
a=malloc(100* sizeof *a);
}

Note that the pointer a has a scope of no larger than this single block
- yet the memory it is made to point to has a duration beyond the
block's execution time. In this case, this causes a memory leak. A
single return a;, which affects neither the scope of the identifier nor,
strictly speaking, the duration of the object, could solve the leak.
Ok,thanks Roose very much.You are a good person , goodness.
I doubt that. His information, in any case, is dubious.
In our here ,I learn from school that basiclly C++ is a extension of
C,and C is a subset of C++,expcept some difference.
That is, alas, a much-held view, but it's wrong. _Good_ C++ is
fundamentally different from good C. It is, indeed, possible to write a
restricted kind of C++ which looks like a restricted kind of C, but in
the general case the result will be bad C, and AFAICT worse C++.
Maybe it is that my teacher do not express that clearly


All too many teachers don't know what the blazes they are on about, and
all too many teachers do indeed think that they know C == C++ minus
classes, which is patently and obviously false.

Richard
Nov 13 '05 #14
wwj wrote:

[OT] Please don't top-post (corrected)
Bruno Desthuilliers <bd***********@removeme.free.fr> wrote in message news:<3f***********************@news.free.fr>...
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...
(snip)
and the difference between the heap and the stack,


This has nothing to do with the C language.

Bruno ,Anyway firstly I thank you ,it's my wrong to post it here and
now yet I can not tell from c and c++ well.
They are two distinct languages, even if they share some common parts.
C++ as been designed to be as compatible as possible with the C language
as it was by the time, so some C source may be compiled in C++ as is or
with little modification, but still they are really two distinct languages.
Then,I want to say that
our world is developing ,all developing,and the language c not be
invent from uk or by you or Christian Bau,
None of us three would claim to have invented this language.
ple you do not regulate(this
word not proper) it
As regular readers (me) or regular posters (some other here) of this
newsgroup, we do regulate it in order to keep a good signal/noise ratio.
This (auto) regulation makes this group one of the best places around to
learn C.
or sneer at others (new one) or rave at others .


Ok, it's usenet here and we usually go straight to the point. I
understand this may seem a bit harsh at first, but you'd better get used
to it !-)

According to the usenet standards, I think that my answer was quite
polite, as I did take the time to explain why you were OT here and even
tried to partially answer your question and give you some useful hints.

Bruno

Nov 13 '05 #15
wwj <ww*******@mail2.swjtu.edu.cn> wrote:
i have said its my wrong to post it here !!!!!!!


These people don't care.

You made an error (or errors) and now must be punished because you are
not in the inner circle (http://tinyurl.com/8qpp). They make these same
(non-C related) errors, but would never go after each other the same way
they go after others.

I would suggest that in the future you just ignore them when their
comments refer to anything other then the C language or don't directly
answer your question.

However, they are quite knowledgeable about C and you should feel free
to use this group to extract that knowledge whenever you feel the need.

--
Nov 13 '05 #16
wwj wrote:

In our here ,I learn from school that basiclly C++ is a extension
of C,and C is a subset of C++,expcept some difference.Maybe it is
that my teacher do not express that clearly or I do not understand
that clearly.So sorry for everyone ,I wish this post ends the
heartrending topic,and all not waster time on the confused quarrel.


You are still topposting, which means adding your answer
**before** the quoted text. Your reply goes **after** any quoted
text (or possibly intermixed), so that things read in a logical
order. You should also snip any quotations not germane to your
reply.

Topposting is considered extremely rude in the better newsgroups,
of which this is one.

To correct a misconception, C++ is a different language than C. C
is NOT a subset. If your teacher is telling you otherwise he is
flat out WRONG. You may quote me to him if you wish, as it may
not be politic to contradict him yourself.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #17
Bruno Desthuilliers <bd***********@removeme.free.fr> wrote in message news:<3f***********************@news.free.fr>...
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.


Wrong there are 3 types of memory in C and C++

1) Automatic
2) Dynamic
3 and Static

--
Imanpreet Singh Arora
isingh AT acm DOT org
Nov 13 '05 #18
te*********@BUSThotmailE.Rcom wrote in message news:<1g3wb6i.120yevw1ji5orwN%te*********@BUSThotm ailE.Rcom>...
wwj <ww*******@mail2.swjtu.edu.cn> wrote:
i have said its my wrong to post it here !!!!!!!


These people don't care.

You made an error (or errors) and now must be punished because you are
not in the inner circle (http://tinyurl.com/8qpp). They make these same
(non-C related) errors, but would never go after each other the same way
they go after others.

I would suggest that in the future you just ignore them when their
comments refer to anything other then the C language or don't directly
answer your question.

However, they are quite knowledgeable about C and you should feel free
to use this group to extract that knowledge whenever you feel the need.

--


Wow you seem to allow all those 'killer bees' who just want to suck
you for their own good. Thank you very much. This is a community. In
every community be it dog or cat or lion or tiger or even human we
tend to protect members of community. Look around you and see how many
peopled do YOU listen too.

"Hello my name is Imanpreet?"

Will you respond..
--
Imanpreet Singh Arora
isingh AT acm DOT org

Proud to be a part of c.l.c community. BZzzzzzzzzzzzzzzzzzzzzzzzzzz
Nov 13 '05 #19

"Minti" <mi************@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
Bruno Desthuilliers <bd***********@removeme.free.fr> wrote in message news:<3f***********************@news.free.fr>...
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,
In block scope. Storage defined at file scope is has static
storage duration by definition.
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.


Wrong there are 3 types of memory


That's 'storage duration'.
in C and C++

1) Automatic
2) Dynamic
3 and Static


Yes there are, but I don't think Bruno's message was 'wrong'.

The acknowledgement of the existence of apples and oranges
does not imply denial of the existence of bananas. I didn't
see Bruno say 'only' automatic and dynamic (actually the formal
term for the latter is 'allocated' (6.2.4)).

-Mike
Nov 13 '05 #20
On 4 Nov 2003 02:13:44 -0800, in comp.lang.c ,
ww*******@mail2.swjtu.edu.cn (wwj) wrote:
Ok,thanks Roose very much.You are a good person , goodness.
no comment.
In our here ,I learn from school that basiclly C++ is a extension of
C,and C is a subset of C++,
This is a very badly wrong piece of learning. C is NOT a subset of
C++, and nor is C++ an extension of C. They're different languages.
expcept some difference.Maybe it is that my
teacher do not express that clearly or I do not understand that
clearly.So sorry for everyone ,I wish this post ends the heartrending
topic,and all not waster time on the confused quarrel.


No problem. but please don't take Roose as a good teacher. He's not.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #21
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<4C*****************@newsread4.news.pas.earth link.net>...
"Minti" <mi************@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
Bruno Desthuilliers <bd***********@removeme.free.fr> wrote in message

news:<3f***********************@news.free.fr>...
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,
In block scope. Storage defined at file scope is has static
storage duration by definition.
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.


Wrong there are 3 types of memory


That's 'storage duration'.
in C and C++

1) Automatic
2) Dynamic
3 and Static


Yes there are, but I don't think Bruno's message was 'wrong'.

The acknowledgement of the existence of apples and oranges
does not imply denial of the existence of bananas. I didn't
see Bruno say 'only' automatic and dynamic (actually the formal
term for the latter is 'allocated' (6.2.4)).

An incomplete statement is an incomplete statement. The
acknowledgement that apples and oranges are the fruits on this earth
does seem to be incomplete. I didn't see Bruno say 'these are the
subset of the storage types' automatic and ****allocated****[if that
is the way you want it ;-)]
BTW if you look carefully at the header he had indeed asked for
*correction* just in case you did not see here it is
""""
#include <regulars_please_correct_me_if_necessary.h>
""""

Maybe he asked for *only* regular regulars then in that case I am
sorry for jumping in your business.

Period.

--
Imanpreet Singh Arora
isingh AT acm DOT org
Nov 13 '05 #22
"Minti" <mi************@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<4C*****************@newsread4.news.pas.earth link.net>...
"Minti" <mi************@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
Bruno Desthuilliers <bd***********@removeme.free.fr> wrote in message

news:<3f***********************@news.free.fr>...
[snip]
> #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,


In block scope. Storage defined at file scope is has static
storage duration by definition.
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.

Wrong there are 3 types of memory


That's 'storage duration'.
in C and C++

1) Automatic
2) Dynamic
3 and Static


Yes there are, but I don't think Bruno's message was 'wrong'.

The acknowledgement of the existence of apples and oranges
does not imply denial of the existence of bananas. I didn't
see Bruno say 'only' automatic and dynamic (actually the formal
term for the latter is 'allocated' (6.2.4)).

An incomplete statement is an incomplete statement.


But 'incomplete' does not mean 'incorrect'.

You responded to Bruno with "Wrong there are 3 types..."
Bruno did not say "there are two types". He simply
enumerated two of the three.

His exact words from above:

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

The
acknowledgement that apples and oranges are the fruits on this earth
does seem to be incomplete.
It was an analogy, meant to convey the statement: "Acknowledgement
of the existence of one or more entities does not imply denial
of existence of others."
I didn't see Bruno say 'these are the
subset of the storage types' automatic and ****allocated****[if that
is the way you want it ;-)]
No he didn't say that. See above. You're assuming that
his list was exhaustive when he didn't specifically say so.

BTW if you look carefully at the header he had indeed asked for
*correction* just in case you did not see here it is
What he said was, as you note, incomplete, but not incorrect.
E.g. "C has data types 'int' and 'long'" is a correct (albeit
'incomplete') statement. But it does *not* imply that C has
no other data types.

""""
#include <regulars_please_correct_me_if_necessary.h>
Right. What he said was not incorrect.
""""

Maybe he asked for *only* regular regulars then in that case I am
sorry for jumping in your business.
The content of (and replies thereto) all messages in a Usenet
newsgroup are, by definition, the business of anyone and
everyone who cares to read (and/or respond to) it/them.
Public forum, and all that.
Period.


Semicolon. :-)

-Mike
Nov 13 '05 #23
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<Ec*****************@newsread4.news.pas.earth link.net>...
"Minti" <mi************@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
"Mike Wahler" <mk******@mkwahler.net> wrote in message

news:<4C*****************@newsread4.news.pas.earth link.net>...
"Minti" <mi************@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
> Bruno Desthuilliers <bd***********@removeme.free.fr> wrote in message
news:<3f***********************@news.free.fr>...
[snip]
> #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,

In block scope. Storage defined at file scope is has static
storage duration by definition.

> 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.
>
> Wrong there are 3 types of memory

That's 'storage duration'.

>in C and C++
>
> 1) Automatic
> 2) Dynamic
> 3 and Static

Yes there are, but I don't think Bruno's message was 'wrong'.

The acknowledgement of the existence of apples and oranges
does not imply denial of the existence of bananas. I didn't
see Bruno say 'only' automatic and dynamic (actually the formal
term for the latter is 'allocated' (6.2.4)).

An incomplete statement is an incomplete statement.


But 'incomplete' does not mean 'incorrect'.

You responded to Bruno with "Wrong there are 3 types..."
Bruno did not say "there are two types". He simply
enumerated two of the three.

His exact words from above:

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

The
acknowledgement that apples and oranges are the fruits on this earth
does seem to be incomplete.


It was an analogy, meant to convey the statement: "Acknowledgement
of the existence of one or more entities does not imply denial
of existence of others."
I didn't see Bruno say 'these are the
subset of the storage types' automatic and ****allocated****[if that
is the way you want it ;-)]


No he didn't say that. See above. You're assuming that
his list was exhaustive when he didn't specifically say so.

BTW if you look carefully at the header he had indeed asked for
*correction* just in case you did not see here it is


What he said was, as you note, incomplete, but not incorrect.
E.g. "C has data types 'int' and 'long'" is a correct (albeit
'incomplete') statement. But it does *not* imply that C has
no other data types.

""""
#include <regulars_please_correct_me_if_necessary.h>


Right. What he said was not incorrect.
""""

Maybe he asked for *only* regular regulars then in that case I am
sorry for jumping in your business.


The content of (and replies thereto) all messages in a Usenet
newsgroup are, by definition, the business of anyone and
everyone who cares to read (and/or respond to) it/them.
Public forum, and all that.
Period.


Semicolon. :-)


Wow!! Years posting here does IMO gives you more experience in
replying with irrelavent arguments. Wait till I stay here for a couple
of years. Next time I hope that if someone makes a wrong statement
OOOPs sorry an INCOMPLETE statement I would quantify as to how much
INCOMPLETE it is. Like is it a nit_pick or pit_pick or khit_pick or
mike_whahler_pick. Arranged in the increasing order of incompleteness.
Quite an exaggeration I know but Hey I have some exprience here now.

--
Imanpreet Singh Arora
isingh AT acm DOT org
Nov 13 '05 #24
"Minti" <mi************@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...

Wow!! Years posting here does IMO gives you more experience in
replying with irrelavent arguments.


I think my 'argument' is quite relevant.

Programming depends upon logic. Your remarks seemed to
me to be somewhat lacking in logic. I pointed this out.

Of course you're free to disagree, which apparently you do.

-Mike
Nov 13 '05 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: wwj | last post by:
Hi ,all I want to know the difference between char a and char *p=new char and the difference between the heap and the stack ,and if the char a is corresponding to the stack in MEMORY,and char...
7
by: Paul | last post by:
Say I have: char foo; char** bar; In my understanding, these two have the same meaning in memory. Could someone elucidate upon these two types and their meanings? Thanks, Paul
9
by: bill | last post by:
Forget the exact definition of difference between, #include <foo.h> and #include "bar.h" Normally foo.h is a standard header file, so it's path is not defined in compiler option, but I...
10
by: tinesan | last post by:
Hello fellow C programmers, I'm just learning to program with C, and I'm wondering what the difference between signed and unsigned char is. To me there seems to be no difference, and the...
61
by: academic | last post by:
When I declare a reference variable I initialize it to Nothing. Now I'm wondering if that best for String variables - is "" better? With Nothing I assume no memory is set aside nor GC'ed But...
7
by: iamchiaweilin | last post by:
Hello all: What's the difference between p and q in the following statements? char p = "Hello"; char *q = "Hello"; I know q stores the address of 'H'. Question is: does p store the...
13
by: In a little while | last post by:
thanks
3
by: artifact.one | last post by:
Hi. What's the practical difference between: #include <header.h> and: #include "header.h"
13
by: manish sahu | last post by:
difference between calloc() and malloc()
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.