473,395 Members | 1,541 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,395 software developers and data experts.

assig array != struct ?

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
3 1548
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sam | last post by:
Hello all I have a two dimensional array (the dimensions are not known) that needs to be passed to fortran from c++, allocate the dimensions of the array in fortran code, do some filling up of...
10
by: Kieran Simkin | last post by:
Hi, I wonder if anyone can help me, I've been headscratching for a few hours over this. Basically, I've defined a struct called cache_object: struct cache_object { char hostname; char ipaddr;...
6
by: Eric Smith | last post by:
Is a structure containing an incomplete array as its last element (per paragraph 2 of section 6.7.2.1 of ISO/IEC 9899:1999 (E)) itself an incomplete type? That appears to be indicated by paragraph...
1
by: mrhicks | last post by:
Hello all, I need some advice/help on a particular problem I am having. I have a basic struct called "indv_rpt_rply" that holds information for a particular device in our system which I will...
10
by: Adam Warner | last post by:
Hi all, With this structure that records the length of an array of pointers as its first member: struct array { ptrdiff_t length; void *ptr; };
5
by: Cybertof | last post by:
Hello, Is it possible to convert a VB6 Array of Struct to a C# Array Of Struct ? The test context is a C# application calling a VB6 ActiveX DLL Function using UDT (User Defined Type) and...
7
by: Sam | last post by:
Hello I have a structure called Company. struct Company { char *employee; char *employee_address; }; I want to build an array of this structure but the number of employees will change...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
20
by: Cyn | last post by:
Hi, I want to create a general array structure which can hold all types. Something like this: struct ARRAY { void **array; size_t size; };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.