NVIDIA Interview Question
3 ways:
(1) y = x;
(2) y.a=x.a, y.b=x.b, y.c=x.c
(3) assuming p is a struct pointer.
p = &x;
y = *p;
What is 4th way? Could someone differentiate these alternative methods pros/cons? Thanks.
the 3rd way is wrong. y is a constant address pointing to a struct object in the stack. y cannot be changed.
4 ways I can think of are following:
- tito June 08, 20101) y = x;
2) y.a=x.a, y.b=x.b, y.c=x.c
3) memmove(&y,&x,sizeof(x));
4) memcpy(&y,&x,sizeof(x));