GE (General Electric) Interview Question for Senior Software Development Engineers


Team: HCT-I
Country: India
Interview Type: In-Person




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

The question says answer in detail, so in detail:

1: s1 will be dereferenced
2: s2 will be dereferenced
3: the assignment operator will be called on the dereferenced s1 with the dereferenced s2 as the parameter

- Anonymous December 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assignment operator will be called bcoz both object already constrcuted and we just assigning one object values in other

- satveer December 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Correct answer is that assignment operator will be used in that case - default one generated by compiler or provided by "sample" class designer.
Persons who say that copy constructor would be invoked in that case are wrong. Constructor is supposed to *construct* object and in presented scenario both objects - pointed by s1 and s2 - are already created.

Copy constructor would be called in such scenario:

sample *s1 = new sample();

// here is called copy constructor
sample s2 = *s1;

// also here
sample *s3 = new sample(s2);

// but here is called assignment operator since *s3 was already crated
*s3 = *s1;

- Krzysztof.G December 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The assignment operator of the Sample class would be invoked to copy contents of object pointed by s2 to s1.If Sample has dynamically allocated memory then the assignment operator has to be overloaded to do a deep copying.

- Anonymous December 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

adress of s2 will be the same as s1

- dexter May 03, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

will call copy constructor of Sample();

- xiongjunliang December 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

as per my understanding, it will call when we do
{
s1 = s2;
}
please explore more ..i am not getting clear picture of this concept.

- manojvajpai December 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

The answer is correct. s1 = s2 would make the pointer s1 point to the same thing s2 points to. This is different from copying the object (invoking the copy constructor), which is achieved by *s1 = *s2. Often people are confused about this topic if they don't understand the difference between objects themselves and pointers to objects -- there is a very big difference, though! I recommend reading a tutorial on pointers if you don't understand this distinction.

- eugene.yarovoi December 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Contents of S2 wil be copied to the conctents of S1

- Anonymous December 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

value pointed by s1 = value pointed by s2

- Anonymous December 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

value pointed by S1 = value pointed by S2

- anyone December 12, 2013 | 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