NetApp Interview Question for Software Engineer / Developers


Country: United States




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

Since it's a normal function, address of the function would be somewhere in the code section of your program. This location is the same for all instances of the class. In fact, it has got nothing to do with the instantiation of object. Because the function would be same across all the objects of the same class.

For a normal member function storage isn't required since the address is known at compile time (or, at the latest, at link time); it therefore doesn't have to be stored separately at runtime.

For virtual functions, the situation is different. Virtual function pointers are stored in an array (called “virtual function-pointer table” or “vtable” for short). Each class has one such vtable and each instance to a class stores a pointer to that vtable. This is necessary because if a pointer/reference of type Base points to a sub-class Derived, the compiler has no way of knowing which function to call; rather, the correct function is calculated at runtime by looking it up in the associated vtable. The vtable pointer is also evident in the sizeof the object.

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

nice explanation

- FIGHTER April 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
4
of 4 vote

First of all this is not a valid code and will end up in compilation error;
The valid code(which i assume that the person who asked the question intended) is

class A {
int a;
void show(){ };
};
int main()
{
A * obj = new A();
printf("\n object size = %d", sizeof(A));
return 0;
}

- bibhay.vishesh August 01, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

When an object is created as above then only data members size is required(in certain cases like in case of virtual function some more size may be required as for VPTR)....all objects of the class use the same code which is stored at some location and so function's code is related to CLASS and not to OBJECT.

- sweetest October 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

hI

- don October 02, 2010 | 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