Assign one struct to another in C

shreyasva picture shreyasva · Feb 20, 2010 · Viewed 170.2k times · Source

Can you assign one instance of a struct to another, like so:

struct Test t1;
struct Test t2;
t2 = t1;

I have seen it work for simple structures, bu does it work for complex structures?
How does the compiler know how to copy data items depending on their type, i.e. differentiating between an int and string?

Answer

fabrizioM picture fabrizioM · Feb 20, 2010

Yes if the structure is of the same type. Think it as a memory copy.