Hi,
I was wondering how the =operator works for
struct.
When I for example define a struct as follows:
struct point {
int a;
char *c;
};
and create the first struct
struct point p1 = { 10, "Hallo" };
and then create another struct and assign it struct p1
struct point p2;
p2 = p1;
it seams that all elements are copied properly, i.e.
a new variable is created for 'a' but also, what is more interesting,
an independent string char* 'c' is generated since a
modification to p1.c does not affect p2.c.
Does this mean that structs can be assigned by '=' without any
problems even if they contain (pointer to) nested structs as
elements?
Thank you.
Chris
I was wondering how the =operator works for
struct.
When I for example define a struct as follows:
struct point {
int a;
char *c;
};
and create the first struct
struct point p1 = { 10, "Hallo" };
and then create another struct and assign it struct p1
struct point p2;
p2 = p1;
it seams that all elements are copied properly, i.e.
a new variable is created for 'a' but also, what is more interesting,
an independent string char* 'c' is generated since a
modification to p1.c does not affect p2.c.
Does this mean that structs can be assigned by '=' without any
problems even if they contain (pointer to) nested structs as
elements?
Thank you.
Chris
Comment