Structures and Unions Question.
Author Message
Structures and Unions Question.

Consider the following type defenitions:

typedef union {
char str[20];
long longnum;

Quote:
} SomeUnion;

typedef struct {
SomeUnion un;
int next;

Quote:
} SomeStruct;

and consider the following code segment:

SomeStruct mystruct, yourstruct;

strcpy (mystruct.un.str, "Hello world.");
mystruct.next = 55;
yourstruct = mystruct;

Will the assignment of one structure to the other COPY all of the string
in mystruct.un.str to yourstruct.un.str, plus the copying of the integer
next?

Let me ask this general question:  When assigning a structure or a union
to another structure or union respectively, will all the information in
the structure or union be transfered to the other structure or union?  In
other words, will arrays be copied from structure to structure by a simple
assignment.

Sorry for the spagetti question asking method.

/----------------------------------------------------------------------------\
|                                          | /====\  |     |   /===\  |    | |
|    The meek has indeed                   | |    |  |     |  /     ) |    | |
|                                          | |====/  |     |  \       |____| |
|                 inherited the Earth...   | |   \   |     |    \     |    | |
|__________________________________________| |    \  |     | (    \   |    | |

\----------------------------------------------------------------------------/

Sun, 21 Jan 1996 09:01:58 GMT
Structures and Unions Question.

Quote:

>Will the assignment of one structure to the other COPY all of the string
>in mystruct.un.str to yourstruct.un.str, plus the copying of the integer
>next?

>Let me ask this general question:  When assigning a structure or a union
>to another structure or union respectively, will all the information in
>the structure or union be transfered to the other structure or union?  In
>other words, will arrays be copied from structure to structure by a simple
>assignment.

Yes.

ben last

Tue, 23 Jan 1996 15:09:50 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages