Yahoo Interview Question for Software Engineer / Developers






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

www . cs . nyu . edu / ~ xiaojian / bookmark / local / copyCplus . pdf

- Coder December 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

copy constructor can do a deep copy whereas assignment is merely a shallow copy ie references.

- ankurcha December 10, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

wrong...
When not provided, compiler will provide both; which does bitwise copy

- lapak2009 December 22, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

A copy constructor initialises a new object from an already existing object. An assignment operator is used to copy values from one object to an already existing object.
The key difference here is that for assignment operator the target object already exists.

- Musheka December 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Right, that's from Effective C++

- creationw December 28, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think the difference lies in the fact that using a copy constructor allows you to make a deep copy while the assignment operator only makes a shallow copy.

A sample code for copy constructor.. though i have not made use of it for making a deep copy.. will post it soon

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

struct copy_variable
{
public:

int abc_1;
int abc_4;
char abc_2;
char abc_3[10];
copy_variable()
{
}
copy_variable(const copy_variable& some_object):abc_2('a'),abc_1(1000)
{
abc_1 = some_object.abc_1;
strcpy(abc_3,"something");
abc_4 = 0;
cout<<"The values of abc_1, abc_2, abc_3\n" <<abc_1<<abc_2<<abc_3;
}

int char_string ();
};

int main()
{
copy_variable object_1;
copy_variable object_2(object_1) ;
object_1.abc_1 = 100;
object_1.abc_2 = 'm';
strcpy(object_1.abc_3, "the");
object_1.abc_4 = 100;
copy_variable object_3 = object_1;
//cout << "values of object 3 \n"<< object_3.abc_1<<object_3.abc_2;
return 0;
}

- Balaji -- learning C++ January 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry for the wrong code above--

Here s a the proper one
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

struct copy_variable
{
public:

int abc_1;
int abc_4;
char abc_2;
char abc_3[10];
copy_variable()
{
}
copy_variable(const copy_variable& some_object):abc_2('a'),abc_1(1000)
{
abc_1 = some_object.abc_1;
strcpy(abc_3,"something");
abc_4 = 0;
cout<<"The values of abc_1, abc_2, abc_3" <<"\t"<<abc_1<<"\t"<<abc_2<<"\t"<<abc_3<<"\n";
}

int char_string ();
};

int main()
{
copy_variable object_1;
object_1.abc_1 = 100;
object_1.abc_2 = 'm';
strcpy(object_1.abc_3, "the");
object_1.abc_4 = 100;
copy_variable object_2(object_1);
return 0;
}

- Balaji -- learning C++ January 18, 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