C++ interview questions and pitfalls

Started by
60 comments, last by archon 22 years, 1 month ago
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
Advertisement
http://moskalyuk.com/jobs/
if anyone is interested .
A
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

seb is suddenly quite depressed, relaising that he knows diddly squat.
I''d like to see the answers anyway....

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

Bp
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
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
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;}  
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?
quote:Original post by sjelkjd
swap two ints without using a temporary variable.


I think that is what he meant.
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.

This topic is closed to new replies.

Advertisement