Interview Question






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

For this I asnwered that, consider that it was zero...

In that case, three objects of this empty class would have had the same address is it not?

while each object's address should be unique. so in order to keep their address unique compiler need to allocate some minimal amount of memory, that's it allocates 1.

but interviewer did not look convinced, any guesses guys

- Crime_master_GoGo August 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You were right. The interviewer probably wanted to gauge your confidence.

- Anonymous August 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

answer is 1

Its 1 because each object needs address to exist.
So its given bare minimum.

You cant allocated 0 memory and expect the object to exist.

- unicorn August 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One Question : Even this Empty class will have a Constructor , Destructor, Copy Constructor and Default Overloaded = operator. So no more than 1 byte is required to encompass all this ?

- Anonymous August 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Because the function body is associated with the class itself,
not with the object.
For example:

class Agg 
{
   int a;
   int b;
   static int c;
   static int d;

   void show()
	   {a=b;}
};

What do you think will be the size of Agg object?
It will be 8. The space for integers a and b.
Everything else (function bodies and static members) is associated 
with the class itself, and will not be COPIED into every created object of that class.

- sergey.a.kabanov January 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It should be at least 1 byte. Say you have a class of no fields init and you are trying to divide something with the size of class object.
If the size is zero, then it will lead in to issues.

- Anonymous August 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

seriously , divide by a class ????

- Anonymous October 07, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

For an empty class, compiler creates Constructor, destructor, copy constructor and assignment operator.Hence, the memory in code segment is system dependent (depending on if machine is RISC or CISC) and memory occupied in data segment is 1 byte, for the class to be existing.None i guess on BSS because the memory allocated is initialized.On the stack will grow and reduce depending on if the class is instantiated using default constructor, copy constructor. Hope this helps.

- Anonymous January 30, 2011 | 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