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

M

Mark McIntyre

On 4 Nov 2003 02:13:44 -0800, in comp.lang.c ,
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.
 
M

Minti

Mike Wahler said:
Minti said:
Bruno Desthuilliers <[email protected]> wrote in message
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

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.
 
M

Mike Wahler

Minti said:
"Mike Wahler" <[email protected]> wrote in message
[snip]
In block scope. Storage defined at file scope is has static
storage duration by definition.


That's 'storage duration'.


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.

Semicolon. :)

-Mike
 
M

Minti

Mike Wahler said:
Minti said:
"Mike Wahler" <[email protected]> wrote in message
[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.

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.
 
M

Mike Wahler

Minti said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top