Yahoo Interview Question for Software Engineer / Developers






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

Deep Copy --> Make another copy of the variable or class.

Shallow Copy --> Make the pointer point to what the other pointer points to.

- Anonymous September 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Another related question is - if you pass by value and don't write your own copy constructor does that mean that even the pass by value parameter has potential to get modified the original variable ?

- Time pass ! February 19, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if the data member are static then the member wont be affected after passing by value .
but if data member is dynamic the it will be modified when pass by reference .


#include <iostream.h>
#include <conio.h>
class base
{
public :
int a[3];
int *ptr;
base()
{
a[0]=5;a[1]=10;a[2]=20;
ptr=new int[1];
*ptr=100;
}
void display()
{
cout<<a;
}
void vdisplay()
{
cout<< " this is the base virtual";
}
};


int main()
{
void modify(base obp);
base ob1;
cout<<"\n\n "<<" "<<ob1.a[0]<<" "<<ob1.a[1]<<" "<<ob1.a[1]<<" ptr= "<<*ob1.ptr;//5 10 10 ptr=100
modify(ob1);
cout<<"\n\n "<<" "<<ob1.a[0]<<" "<<ob1.a[1]<<" "<<ob1.a[1]<<" ptr="<<*ob1.ptr;//5 10 10 ptr=999
getch();
}
void modify(base obp)
{
obp.a[0]=999;obp.a[1]=999;obp.a[2]=999;*obp.ptr=999;
}
output :
5 10 10 ptr=100
5 10 10 ptr=999

- Amrendra Kumar Verma April 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if the data member are static then the member wont be affected after passing by value .
but if data member is dynamic the it will be modified when pass by reference .


#include <iostream.h>
#include <conio.h>
class base
{
public :
int a[3];
int *ptr;
base()
{
a[0]=5;a[1]=10;a[2]=20;
ptr=new int[1];
*ptr=100;
}
void display()
{
cout<<a;
}
void vdisplay()
{
cout<< " this is the base virtual";
}
};


int main()
{
void modify(base obp);
base ob1;
cout<<"\n\n "<<" "<<ob1.a[0]<<" "<<ob1.a[1]<<" "<<ob1.a[1]<<" ptr= "<<*ob1.ptr;//5 10 10 ptr=100
modify(ob1);
cout<<"\n\n "<<" "<<ob1.a[0]<<" "<<ob1.a[1]<<" "<<ob1.a[1]<<" ptr="<<*ob1.ptr;//5 10 10 ptr=999
getch();
}
void modify(base obp)
{
obp.a[0]=999;obp.a[1]=999;obp.a[2]=999;*obp.ptr=999;
}
output :
5 10 10 ptr=100
5 10 10 ptr=999

- Amrendra Kumar Verma April 13, 2012 | 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