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

what's diffs in the prog?

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+
2 Replies


P: n/a
In article <et**********@news.yaako.com>,
guoliang <po********@gmail.comwrote:
>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)?
One involves arrays, the other involves structs. Assigning structs is legal,
assigning arrays isn't.
>2.why i can't init bbb by bbb.c[5]={2,2,2,2,2};
Pick one of these:

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

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

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

struct { int c[5]; } aaa, bbb;
memcpy(&bbb.c, (int[5]){2,2,2,2,2});

struct foo { int c[5]; } aaa, bbb;
bbb=(struct foo){.c={2,2,2,2,2}};

struct foo { int c[5]; } aaa, bbb;
bbb=(struct foo){{2,2,2,2,2}};

--
Alan Curry
pa****@world.std.com
Mar 16 '07 #2

P: n/a
guoliang wrote:
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};
because this is assignment not initialisation, although the syntax
looks superficially similar they are not the same thing.
--
Nick Keighley

Mar 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.