By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

assig array != struct ?

P: n/a
hi:
in c,i use :

int a[5],b[5]={1,2,3,4,5};
struct {
int c[5];
}aaa,bbb;

bbb.c[0]=bbb.c[1]=bbb.c[2]=bbb.c[3]=bbb.c[4]=2;

1) a=b; //compile error;
2) aaa=bbb

1.what's differ between 1),2)?
2.why i can't init bbb by bbb.c[5]={2,2,2,2,2};

thx!!

Mar 16 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
la*********@gmail.com said:
hi:
in c,i use :

int a[5],b[5]={1,2,3,4,5};
struct {
int c[5];
}aaa,bbb;

bbb.c[0]=bbb.c[1]=bbb.c[2]=bbb.c[3]=bbb.c[4]=2;

1) a=b; //compile error;
2) aaa=bbb

1.what's differ between 1),2)?
You can't assign to an array. You /can/ assign to a struct. Why? Well,
because. There doesn't seem to be any better reason than that. It's
just one of them things.
2.why i can't init bbb by bbb.c[5]={2,2,2,2,2};
struct {
int c[5];
} aaa, bbb = { { 2, 2, 2, 2, 2 } };

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 16 '07 #2

P: n/a
On 3月16日, 下午1时54分, Richard Heathfield <r...@see.sig.invalidwrote:
langog.i...@gmail.com said:
hi:
in c,i use :
int a[5],b[5]={1,2,3,4,5};
struct {
int c[5];
}aaa,bbb;
bbb.c[0]=bbb.c[1]=bbb.c[2]=bbb.c[3]=bbb.c[4]=2;
1) a=b; //compile error;
2) aaa=bbb
1.what's differ between 1),2)?

You can't assign to an array. You /can/ assign to a struct. Why? Well,
because. There doesn't seem to be any better reason than that. It's
just one of them things.
2.why i can't init bbb by bbb.c[5]={2,2,2,2,2};

struct {
int c[5];

} aaa, bbb = { { 2, 2, 2, 2, 2 } };

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999http://www.cpax.org.uk
email: rjh at the above domain, - www.
thx rjh!!
but the answer without reason.
if i want to change the value of bbb ,how to do it simply?
can u figure the c's object modle in memory?

Mar 16 '07 #3

P: n/a
la*********@gmail.com wrote:
On 3月16日, 下午1时54分, Richard Heathfield <r...@see.sig.invalidwrote:
langog.i...@gmail.com said:
in c,i use :
Could you not not use abbreviations like "u"? It is clearer if you use
"I"
rather than "i". Things are clearer if you use standard english rather
than
txt-speak.

Also don't post the same thing multiple times.
int a[5],b[5]={1,2,3,4,5};
struct {
int c[5];
}aaa,bbb;
bbb.c[0]=bbb.c[1]=bbb.c[2]=bbb.c[3]=bbb.c[4]=2;
1) a=b; //compile error;
2) aaa=bbb
1.what's differ between 1),2)?
You can't assign to an array. You /can/ assign to a struct. Why? Well,
because. There doesn't seem to be any better reason than that. It's
just one of them things.
2.why i can't init bbb by bbb.c[5]={2,2,2,2,2};
struct {
int c[5];

} aaa, bbb = { { 2, 2, 2, 2, 2 } };

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999http://www.cpax.org.uk
email: rjh at the above domain, - www.
don't quote .sigs (anything after "--<space>") unless you are
commenting
on them

but the answer without reason.
yep. The answer is "because" or "ask Dennis" (the designer of the
language).

if i want to change the value of bbb ,how to do it simply?
I suppose you could set up a default value.

struct
{
int c[5];
} aaa, bbb, def_bbb = { { 2, 2, 2, 2, 2 } };

/* do things to bbb */

/* reset to default */
bbb = def_bbb;

can u figure the c's object modle in memory?
"model"? Why? Why do you need to know this? What are you trying to do?
The ints of C will be in increasing order in memory. Some types may
need padding
between the array elements, but this is unlikely with ints.
--
Nick Keighley

Mar 16 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.