Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

archon

C++ interview questions and pitfalls

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello Folks, I have a technical interview this week for a position requiring a bit more C++ than I have. I''ve spent today and friday reading, and my brain is a little fried right now. Anyways, I''m trying to laser beam on what to spend my remaining time studying and... my question is this: I was wondering if you all would be so kind as to post tough questions, trick questions that you would think would stump someone like me (I''ve been programming java professionally for a while, and this would be my first foray into professional C++), questions about thorny bits of theory and exceptions to the rules and crazy function declarations and lots of stuff that I probably don''t even know, about C++ (along with the answers preferrably Anything along these lines would be a big help. TIA! Archon

Share this post


Link to post
Share on other sites
Advertisement
Write atoi without using any built in libraries.

Reverse a char * string in place.

swap two ints without using a temporary variable.

Give a linked list, determine if it has a cycle.

Why is it better to use a function object over a function pointer for the STL sort(or any other stl algorithm for that matter)?

When a class has a virtual destructor, what does that imply? what if its destructor is non-virtual?

Say you''re making a class heirarchy of shapes. Should rectangle be derived from square?
What about square from rectangle?
Why?

State one case in which the code would clearly benefit from the presence of a goto.

Compare the design methodologies for the STL with the Java collections library. What are the design goals? Why were each designed the way they were?

If you could add one feature to the C++ language, what would it be?

If you could remove one feature from the c++ language, what would it be?

How would you provide behavior like the ''finally'' statement from java, in c++?

given the following class, in what order are the constructors called?

class X
{
X::X(string name,int size);
vector v;
int size;
string name;
}

X::X(string nm,int sz):
size(sz),v(size),name(nm)
{
//nothing to do
}

bonus points: what''s the bug in the code?

That''s a bunch for now, if you need them i''ll post answers later

Share this post


Link to post
Share on other sites
I''d like to see the answers anyway....

See how much of the reasoning in my head is right (very little I suspect!)

Bp

Share this post


Link to post
Share on other sites
I'm dying to see the answers to some of those....
Actually I'm gonna to answer them myself (offline)

oh yeah and the bug is in the declaration of the constructor

Edited by - ChaosEngine on February 19, 2002 11:13:18 AM

Share this post


Link to post
Share on other sites
In the following code, what will the output be:

  
int main(int argc, char *argv[])
{
char *lpString = "abcdefghijklmnopqrstuvwxyz";
int nNumber = 0;

for(int i=0; i < 8; i++){
cout << nNumber[lpString];
nNumber += i;
}
cout << endl;

return 0;
}

Share this post


Link to post
Share on other sites
Not strictly C++, but you answer it in C++. This question was asked at my job interview.

Say you have two variables "a" and "b". How would you exchange the contents of these two variables without using any other intermediate storage?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by sjelkjd
swap two ints without using a temporary variable.



I think that is what he meant.

Share this post


Link to post
Share on other sites
name all the uses of static.

name all the uses of const.

Very simple, about 80% of applicants I saw when interviewing couldn''t answer.

Then there''s my infamous "clear_bit" question. Search for the thread entitled "Horrible Interviews" if you want to go over some old discussion.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!