# Typical (technical) interview questions

This topic is 4856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm going through the interview process right now and I'm trying to get fully prepared. There are a handful of questions that get asked the majority of the time and I figured this thread could be a good resource. I'm interested in technical questions only. Questions and answers would be best (as this is a study resource). But posting questions for the smart people here at gamedev to answer would also be quite helpful. Even just laying out some examples of tricky/obscure topics would be good (describing c++ casting or the meaning of volitile, etc implementation for example). Have at it! Thanks

##### Share on other sites
Here's a question that has been asked I'd say rougly 80% of my interviews. My answers are always pretty rough (and I think un-impressive).

Q: What does a constructor do? A destructor?

A: ?

As low level and as much detail as possible please! I understand at a higher level but I've just never had much cause to dig any deeper (such as what memory management, stack/heap, etc stuff is going on under the hood).

##### Share on other sites
Hmm.. lots of interviews eh? Interesting.

Explain polymorphism.

##### Share on other sites
Here's one that has been asked in 98% of my interviews:

Q: What is the dot product and what is it used for? Cross product?

A: The following is my answer, feel free to comment.

Dot Product: This calculation is commonly used to find the measure of the angle between two vectors. Such a calculation requires that the vectors be unit vectors, however, or else the result will be inaccurate. For certain purposes, such as backface culling, the actual dot product is ignored and only its sign is used. The reason for this is because the sign of the dot product has the following significance:
If V . W > 0 then 0 < 90 	^^ == 1	 (same direction)If V . W = 0 then 0 = 90	^> == 0	 (orthogonal)If V . W < 0 then 0 > 90	^v == -1 (opposite directions)

Therefore, the sign of the dot product can tell you which side of the view vector the polygon resides in.
if θ > 90, don’t cull (or reverse the view vector to remain consistent – θ < 90)
The dot product of two vectors is defined as:
X = V . W = V1W1 + V2W2 + V3W3

u • v = |u| |v| cos θ (if u and v are unit vectors, the magnitudes are 1 and can be ignored)
A vector dotted by itself measures the square of its length. |v| = (v • v)

Cross Product: of two vectors is defined as:
X = V x W  = (X1, X2, X3)  = (V2W3 - V3W2, V3W1 - V1W3, V1W2 - V2W1)  = (YVZW – ZVYW), (ZVXW – XVZW), (XVYW – YVXW)	[if V = (XV, YV, ZV) and W = (XW, YW, ZW)]i	j	k	To find i component, (V2 * W3) – (V3 * W2)V1	V2	V3	To find j component, (V3 * W1) – (V1 * W3)W1	W2	W3	To find k component, (V1 * W2) – (V2 * W1)

This cross product can be used to find the normal of a polygon in 3D. The normal of any surface is a vector perpendicular to the surface. The normal can be calculated by taking the cross product of two vectors (V1 and V2), which are defined from three (non-collinear) vertices of the polygon.
Because the normal is exactly perpendicular to the polygon, it can be used in such processes as light source shading and backface culling. However, certain processes (such as light source shading) require that the polygon normal be a unit vector, in which case you must normalize the polygon normal after the cross product calculation.

The magnitude of the cross product is area of the parallelogram between the two vectors.
Area = | u | | v | sin θ

##### Share on other sites
Quote:
 Original post by Anonymous PosterHmm.. lots of interviews eh? Interesting.Explain polymorphism.

I'm a professional when it comes to being laid off. :( I'm quite used to the interview process although I still never seem to get any better at it. I'm in the job hunt at least once a year -- sometimes more.

I have a review sheet I use so I'm just copying off. I've been asked about polymorphism pretty often as well so here is that section hehe:

VIRTUAL:
A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class.

The derived class can either fully replace ("override") the base class member function, or the derived class can partially replace ("augment") the base class member function. The latter is accomplished by having the derived class member function call the base class member function, if desired.

Dynamic binding/static typeing
When you have a pointer to an object, the object may actually be of a class that is derived from the class of the pointer (e.g., a Vehicle* that is actually pointing to a Car object; this is called "polymorphism"). Thus there are two types: the (static) type of the pointer (Vehicle, in this case), and the (dynamic) type of the pointed-to object (Car, in this case).

Static typing means that the legality of a member function invocation is checked at the earliest possible moment: by the compiler at compile time. The compiler uses the static type of the pointer to determine whether the member function invocation is legal. If the type of the pointer can handle the member function, certainly the pointed-to object can handle it as well. E.g., if Vehicle has a certain member function, certainly Car also has that member function since Car is a kind-of Vehicle.

Dynamic binding means that the address of the code in a member function invocation is determined at the last possible moment: based on the dynamic type of the object at run time. It is called "dynamic binding" because the binding to the code that actually gets called is accomplished dynamically (at run time). Dynamic binding is a result of virtual functions.

##### Share on other sites

C++ casting

static cast
Conventional casting of one type to another, where there is some meaning to what the cast will do. (Thus, normally you can't cast from a Foo to a Bar, unless there's a definition for how to do this). Casting from one type to another is interesting, particularly, casting float to int. Like the unary minus, the casting operation does NOT change the value of the variable it is casting. Instead, like unary minus, it creates a temporary value which is the casted result.

dynamic cast
Meant for downcasting from a base class to a derived class. This check is done at runtime (as opposed to static casting which can generate the necessary code to do the casting at compile time). Will return NULL if unable to cast.

const cast
To temporarily add or remove constness from a const variable. Mostly used to get rid of warnings about violating constness.

reinterpret cast
To allow you to cast one pointer type to another pointer type to another. Since all pointers are addresses, and all addresses have the same number of bytes (at least, on a given ISA), the casting does not convert any bits. C++ decided to call this pointer-to-pointer casting, reinterpret_cast. What's being reinterpreted is the meaning of the bytes. When reinterpeting that pointer to a Bar * pointer, those bytes of the Foo object are unchanged.

##### Share on other sites
Are there any free sources where one can study the low-level details of these higher-level features of OOP which we take for granted? Is there a single textbook reference (nonfree) which is recommended?

##### Share on other sites
Quote:
 Original post by helixHere's a question that has been asked I'd say rougly 80% of my interviews. My answers are always pretty rough (and I think un-impressive).Q: What does a constructor do? A destructor?A: ?As low level and as much detail as possible please! I understand at a higher level but I've just never had much cause to dig any deeper (such as what memory management, stack/heap, etc stuff is going on under the hood).

A constructor is a function that is run on a section of memory that is allocated, either on the stack, or the heap. It's purpose is to set up an object of whatever class it is part of. Using the constructor, data members of a class can be initialized and their value changed from whatever garbage value is given to the memory by the operating system before it was allocated. The constructor is run before the object it is intended to construct can be used.

A destructor is called on an object when it is deleted. This means whenever a local variable of a class type that has a destructor defined goes out of scope, or an object is delete from the heap. They are usually used to delete memory that was dynamically allocated for that object.

##### Share on other sites
Q: What is a pure virtual method in C++?

Me: You dont have to define a pure virtual method of a class, only declare it, but you have to define it in a child class to instanciate it. Usually it is used to create interfaces of classes.

Q: Ok, but CAN you define it in the mother class?

Me: ... why would you do that?

I felt a bit of an idiot not knowing that one. Yes, you can :P Beware of the answers you give! little side-story:

In my first year of college, I had a very tough technical interview for an internship. Didnt get it (got 4th place, a third year got the job). Three years and a half later, I interview them again for my final internship. Guess what, they had a list of every question they asked me three years before with the answers I gave them then. Told me they wanted to see if I learned anything lol! (got 2nd place, too bad).

##### Share on other sites

what is virtual inheritence?
What's the difference between a pointer and a reference?
what's the difference between prefix and postfix operators?
what is a virtual constructor?
why shouldn't you inherit from the standard library containers?

all usually followed by:
and what makes you think we're gonna pay you that much? [grin]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 23
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
634782
• Total Posts
3019267
×