Goldman Sachs Interview Question for Applications Developers


Country: United States
Interview Type: Phone Interview




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

d)
the step of constructing the object obj1:
1. allocating space for obj1;
2. call the base-class (A) constructor to initialize the base-class parts of the obj1
3. initializing the member of derved-class (B): var2( d++) , a(var2++)
so before initializing B member, the A's constructor is called, at that moment, nothing is given to the 'var1' of A class

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

a(var2++) *is* the initialization, but do you know the value of var2 ? :) It is undefined, hence var1 is also undefined. var2 will get value 5 only after class a has been initialized. Hence, if you would have print value of var2, it will be 5.

- tarun16 June 24, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

d) undefined
because execution of initialization list will be done from left to right. so first
a(var2++)
this statement will execute & it will pass a garbage value of var2. Then
var2( d++)
this statement will execute & will initialize var2's value as 5.
So at the end
var1 will be having a garbage/undefined value
var2 will be having value 5.

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

execution of initialization list happens from left to right.
If we have 3 list argument like,

class B : public A { 
	int b, c;
	public: 
		B(int x): b(x), c (++b), A(b++) {
			printf("ctor of class B: %d\n", b, c); 	
	}
}

First A(++b) will get called!, as it is base class constructor, then rest of the argument list will get called from left to right, i.e. b(x), then c(++b).
If we do not pass A(++b) in argument list of B(), then default constructor will be passed.

- flipper April 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes that's sound gud

- sohit April 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

yeah you are right..... execution of initialization list happens from left to right.

But for the above code, garbage value will be assigned to the base class's variable var1.

- kuber April 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

left to right or right to left....?it seems it execute from right to left...

- gr81 April 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

the order of initialization is not left to right or right to left. Rather it is the order in which it is declared in the class.

either way, here base class get initalized first and so it's undef..

- kentbarn April 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Exactly, the order of initialization will be first the base class and then the emmbers in the order in which they are declared in the class. The order in the initialization list does not matter

- Amaze May 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote
guys please please use braces {{{ } }} for code, so we can understand what you are asking. - Rams April 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

5

- yerrasaichandra June 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

5

- Harsh April 09, 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