structure assignment vs memcpy

S

subramanian100in

Suppose I need to assign one structure to another.
Should each member of the structure be assigned individually or can
memcpy be used ?

Since the compiler can add padding bytes, which approach is always
safer ?
 
S

santosh

Suppose I need to assign one structure to another.
Should each member of the structure be assigned individually or can
memcpy be used ?

Since the compiler can add padding bytes, which approach is always
safer ?

Simply assign one object to another with the assignment operator.
Structure assignments have been supported since C90.

Of course if you only want to assign some members of a struct object
to another, then you'll have to do it manually.

Using memcpy is not usually necessary, since the language directly
supports copying structures.
 
R

Richard Tobin

Suppose I need to assign one structure to another.
Should each member of the structure be assigned individually or can
memcpy be used ?

There seems to be a whole bunch of you doing the same course, asking
the same questions over and over again. Why don't you get together and
nominate one of you to do all the homework?

-- Richard
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top