I am more confused with structures. There are many ways to copy a structure.
struct complex
{
int real;
int imaginary;
};
Assume c1 is complex structure v
memcpy(&c1.real, &c2->real, sizeof(struct complex))
is very strange, since bots types are atomic, there is no need for that kind of copying. Also sizeof(struct complex)
is wrong, because it should have been sizeof(int)
(which is only 1/2 size of the whole structure)
Simple assignment is enough:
c1.real = c2->real;