Microsoft Interview Question for Applications Developers


Country: India
Interview Type: In-Person




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

I don't believe there's any difference between how structs and classes are laid out in C++. Generally, people don't use inheritance for structs, so there will probably be no virtual table pointer, but whether to use inheritance or not is completely up to the programmer. See this StackOverflow thread: stackoverflow DOT com/questions/979211/struct-inheritance-in-c

Classes and objects are completely different things (objects have instance variables, pointers to vtables, etc. while classes have class variables and the actual vtables).

- eugene.yarovoi September 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What language?

- Anonymous September 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

in c++

- arun September 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Memory allocation happens in stack and heap in struct and class. refer to memory allocation and garbage collection in .net for further references. for specific languages you may refer to specific specs. In general stack and heap allocation for most of the languages.

- Bala September 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Reference types are always allocated on the heap - class, interface, delegate, object, string.

Value types (e.g. struct) and pointers are allocated depending on where they are declared. If declared within a method body, then they go on the stack. If declared outisde a method, e.g. as class variables, then they go on the heap.

- Xiang September 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

That's not right. In C++, if you make a class by value (i.e. MyClass m; ), it will be allocated on the stack.

- eugene.yarovoi September 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I should have mentioned C# for my case though I believe C++ is the same. When you do "MyClass m" within a method, you are just declaring a pointer, not allocating memory on the heap like with "new".

- Xiang September 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

That's absolutely not true. In C++, when you say MyClass m; you are making a new object (calling the zero-argument constructor) that will be stored on the stack. A full object is created -- not just a pointer! That's how C++ works. If you wanted to make a pointer, you'd have to say MyClass* m;

The OP of this question has said it's a C++ question.

Also, please read this post called "The stack is an implementation detail". I see this sort of misconception all the time. Whether something is placed on the stack or heap isn't really determined by its type:

blogs DOT msdn DOT com/b/ericlippert/archive/2009/04/27/the-stack-is-an-implementation-detail.aspx

- eugene.yarovoi September 10, 2012 | 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