Goldman Sachs Interview Question for Applications Developers


Country: India
Interview Type: In-Person




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

1. The standard does not allow objects (and classes thereof) of size 0, since that would make it possible for two distinct objects to have the same memory address. That's why even empty classes must have a size of (at least) 1.

2. Default constructor, Copy constructor, Copy-assignment, Destructor, Move constructor, Move-assignment operator

3. Yes it depends on CPU architecture. It will at least be 1 byte.

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

So what will be the size of empty class on 64 bit hardware?

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

To ensure that the addresses of two different objects will be different.that is the reason "new" always returns pointers to distinct objects.

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

Thanks for the answer......is it documented anywhere...if so, please provide the link?

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

You can find the info at stroustrup's bs_faq2
Google for stroustrup's bs_faq2. Links are not allowed on Careercup.

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

Thanks for providing the information...

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

for ur 2nd query,
constructor, destructor, copy constructor and = operator

IMHO, could be depend on CPU architecture

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

for ur 2nd query,
constructor, destructor, copy constructor and = operator

IMHO, could be depend on CPU architecture

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

For the third question, does it really depends on machine architecture? I don't think so, because it has to allocate min memory (i.e one bye) to distingush between two objects. Except that I don't see any other reason. If that is the case, why it depend on the archtecture. Byte is always in any machine.

- Ding May 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Size of an empty class is not zero. It is 1 byte generally. It is nonzero to ensure that the two different objects will have different addresses. See the following example.

#include<iostream>
using namespace std;
 
class Empty { };
 
int main()
{
    Empty a, b;
 
    if (&a == &b)
      cout << "impossible " << endl;
    else
      cout << "Fine " << endl;
 
   return 0;
}
Output:

Fine

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

What are the default functions in an empty class?
Constuctor, Destructor, Copy constructor, Assignment operator, Assignment reference operator ) 5 members

does the size of empty class depend upon the compiler or hardware(32 bit or 64 bit)?
It shouldn't.

- MadhaviA September 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

the class can never be empty as it is been extended by the java.lang.Object - So the size of the object can never be zero , because whenever the class is created in that case that class will get extended by the java.lang.Object ..hence which says that the class size can never be zero
- See if the class if empty in that case by default the methods would be like -- constructor and destructor

- shelly jindal June 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

This is C++.

- Satish June 18, 2013 | Flag


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