NVIDIA Interview Question






Comment hidden because of low score. Click to expand.
2
of 2 vote

4 ways I can think of are following:
1) 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));

- tito June 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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.

- Dejected June 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

the 3rd way is wrong. y is a constant address pointing to a struct object in the stack. y cannot be changed.

- chenming831 June 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i tried and it worked. so i think it equals to the simply y = x; just passed by a pointer.

- chenzhaohonggd September 30, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

one way can be this: passing the functions as reference

write a function to copy x into y:
void copy(struct *x,struct *y)
{
*y=*x;
return(void)
}

- Anonymous June 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can also use COPY CONSTRUCTOR in struct??

- ridercoder October 17, 2010 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More