Find the middle element of a singly linked list
What are your favorite coding features about C/C++?
How would you form an index for a book? i.e. finding the words specified, ordering the page numbers per word (needed to discuss data structures a bit)
More tips from Graham at Velocity Reviews dot com.
I know there a good few companies out there that won’t let you in the
door without an A score in brainbench. www.brainbench.com
It’s easy to get a high score if you study. Be prepared to get a lousy
score first time (unless you’re name is victor bazarov), then you’ll
get a feel for the type of questions they ask (you’ll be disgusted the
first time you take the test). The second time round you’ll be prepared
and will score ok. things that they ask include order of construction
for classes that inherit virtually, using set_new_handler correctly,
being able to parse the syntax for pointers to functions e.g. this type
of stuff (except uglier);
int (* minus)(int,int)
other stuff includes the unnamed namespace, ugly pointer arithmetic,
assumptions about the size of various datatypes (whats platform
specific, what isn’t), exceptions, new style casts (with pointers,
references, unrelated types etc, exceptions thrown when casting
pointers versus bad_cast with references, They offer a sample test at;
as Mister Bazarov says it won’t make you a good programmer but it might
get you to interview stage.
For the record I managed to get the top score of all the candidates
interviewed however the test was in no way a good benchmark of my
ability…. I definitely ain’t that good and struggle a lot of the time
(fook I hope that doesn’t come back to haunt me). Start by taking their
sample test if you’re interested. Don’t pay them any money though. If a
company needs a brainbench score before they interview you, they
usually pay. Victor Bazarovs advice is sound, just program if you want
to be profecient.
Brainbench have free C++ tests (and quite a few others)
Loads of interview questions here
Online C++ test here
Look at C/C++ Program Perfometer
that contains various testsuites ( http://lists.sourceforge.net/lists/l…rfometer-users )
Yes have a c++ compiler on hand to retype questions. You have three minutes for each question asked. Do note some questions may be an actual image so that they cannot be copied in text format.
int + char = ?
If you care, you cast. In other words, if this is a significant issue in your code, you’re doing something wrong. You shouldn’t assume that the next person to come along will understand type promotion as well as you do. Incidentally, the result is an int.
How do you declare a pointer to a class method?
Seems like a reasonable question, right? Except then you remember the concept behind encapsulation: you really don’t want to look at the implementation of any method in a class hierarchy, since that can really mess you up if you’re handling an object of the wrong type. In other words, this is just something that’s conceptually impure…and likely to lead to problems when you need to maintain the code. If you really, really need to do this, remember that it’s not void (*class::method)(int, int), the way you might expect — it’s void (class::*method)(int, int). To me, in addition to asking about a questionable practice, it’s also a trick syntax question.
What does the “mutable” modifier do?
This is actually a reasonable, but somewhat obscure, question. It’s used on two ways; one that strikes me as poor practice, and one that is important but uncommon. The mutable modifier makes a member variable non-const under all circumstances; it forms an exception even when the surrounding object has been declared const. This is, in my opinion, a Bad Thing To Do; it changes the state of an object that is supposed to be stable. On a positive note, this can be very important as an optimizer hint when dealing with hardware registers. In such a circumstance, you’re really telling the optimizer to make sure it reads the memory location each time it’s accessed, and not to make the assumption that the value hasn’t changed. So 50/50 here, in my book; the sample in the test is an example of misleading coding practices, but the modifier does have value in specific circumstances.
What is a null namespace and how is it used?
This is an obscure question. Null namespaces, or namespaces that haven’t been given a name, are recent additions to the C++ specification and are unfamiliar to many C++ developers. The functionality wasn’t even supported prior to version 4 of g++. Since gcc 3.4.6 is distributed with RedHat Enterprise Linux version 4, this functionality is not widely available to UNIX/Linux developers yet. It’s also one of those very strange things that periodically make it into the language; I’m sure there’s a good reason that it’s there, but I certainly can’t think of it. Null namespaces provide another mechanism for variable scoping; any variables declared in the un-named namespace are local to the file where they were declared, as if they were static. They are accessed as if they weren’t in a namespace at all.