So I got through a phone interview...

Started by
32 comments, last by Rainault 17 years, 6 months ago
In my experience most programming tests have C questions such as write a reverse function for a singly linked list(or some other function for a similar data structure, in some rare cases write an entire linked list, do an in-place string reversal, etc. Stuff to evaluate your pointer usage/understanding. If you can't perform on the spot you are seriously hurting your interview.

There's no way to tell if a submitted code sample came from the person, though the same could be said for programming tests by email or whatever. Only an idiot would cheat on them though, cuz if you score an on-site interview you will likely be getting a face to face grilling of similar questions, which are much more tense than a written programming test. If you don't know your stuff you're going to look like a fool at that point. I've never been as nervous as hand writing code on a white board in front of 2-3 lead programmers(in the worst case, usually it isn't so bad).
Advertisement
I love C coding tests. There are lots of really, really obscure questions to ask. Most of them are worthless for determining whether someone will make a good game programmer or not, but that doesn't mean they're not fun.

Here are a few good ones:

1.) In what situation would you want to mark a variable "volatile const"?

2.) In a C preprocessor macro, what does ## signify?

3.) What is the output of this code:
int c = 1;
c = ++c + c++ + c + ++c;
printf("%d",++c);

No cheating!
I hate questions like #3. They are retardedly pointless. Anyone writing code like that in production should be slapped.
Quote:Original post by DrEvil
I hate questions like #3. They are retardedly pointless. Anyone writing code like that in production should be slapped.


I guess that question is just to make sure that it would result in undefined behavior, some programmers might write: f(++x,x+1); which doesn't look that bad, but any programmer who have programmed in C for even a short amount of time should tell you that it's really bad.
I've had a couple of interviews in the last week or so where they asked primarily C style questions, despite the fact that both places do most of their coding in C++. The sorts of things I've been asked include:

1. Write a function to reverse a string (char array). Optimize it (looking for the use of pointer arithmetic instead of array indexing).

2. Which of these calls to your function will work, and why?

a)
int main(){    std::string str = "Hello";    reverse(str.c_str(), 5);}


b)
int main(){    char * str = "Hello";    reverse(str, 5);}


c)
int main(){    char str[] = "Hello";    reverse(str, 5);}


3. Implement atoi/itoa.

4. This function returns an approximation (within 1e-6) to the result of a mathematical operation on val. What is that operation?
double f(double val){    double app = 1.0;    double err = 1.0;    while(err > 1e-6)    {        app = (app * app + val) / (2 * app);        err = val/app - app;    }    return app;}

What is the error in the while loop?

EDIT: Added 2.

[Edited by - bakery2k1 on October 3, 2006 7:24:12 PM]
Quote:Original post by CTar
Quote:Original post by DrEvil
I hate questions like #3. They are retardedly pointless. Anyone writing code like that in production should be slapped.


I guess that question is just to make sure that it would result in undefined behavior, some programmers might write: f(++x,x+1); which doesn't look that bad, but any programmer who have programmed in C for even a short amount of time should tell you that it's really bad.


Lets see, I'm guessing that you can't garentee which order the function params are evaluated, so if X was 1 to begin with, occasionally you end up calling f(1, 3) and other times it's f (2, 2). Also, the end result of x would be 2 in the first example, and 3 in the second example.

1.) In what situation would you want to mark a variable "volatile const"?

Pass. I would have thought they conflicted (volatile = variable can be changed outside of the program so don't perform optimizations/predictions on its value, and const should be "don't change it). Unless of course, you are making a pointer volatile const, in which case I think it means the address of the pointer can be changed without the program knowing about it, but you're not allowed to modify the data at that address.

2.) In a C preprocessor macro, what does ## signify?

Argh. IIRC (I haven't used C macros besides #ifndef, #define and #endif for ages) it's used for turning values passed to the macro parameters into strings.

3.) What is the output of this code:
int c = 1;
c = ++c + c++ + c + ++c;
printf("%d",++c);

Does it print 10?


I bet I fail all of them miserably :)
Quote:Original post by MENTAL
1.) In what situation would you want to mark a variable "volatile const"?

Pass.


When *you* shouldn't modify it but the system can and does. I/O mapped memory from hardware comes to mind.

Quote:2.) In a C preprocessor macro, what does ## signify?


Argh. IIRC (I haven't used C macros besides #ifndef, #define and #endif for ages) it's used for turning values passed to the macro parameters into strings.

That's #. ## is token pasting - FOO ## 1 => FOO1.

Quote:3.) What is the output of this code:
int c = 1;
c = ++c + c++ + c + ++c;
printf("%d",++c);

Does it print 10?


Maybe. The correct answer as far as I'm concerned is: "An overwhelming desire to give the writer of that code a swift kick in the crotch for invoking the undefined behavior of modifying the same variable multiple times without a single sequence point."
I just went through this experience not too long ago. Don't be too hard on yourself. They just want to know you *can* infact program, and are able to meet a deadline. Chances are you won't have to know much more than the basics (language wise), but they'll get you to think, and solve some interesting problems.

So when you go in just pretend they've already hired you, and this is your first assignment.

Cheers.
Quote:Original post by Ozymandias42
I love C coding tests. There are lots of really, really obscure questions to ask. Most of them are worthless for determining whether someone will make a good game programmer or not, but that doesn't mean they're not fun.

Here are a few good ones:

1.) In what situation would you want to mark a variable "volatile const"?

2.) In a C preprocessor macro, what does ## signify?

3.) What is the output of this code:
int c = 1;
c = ++c + c++ + c + ++c;
printf("%d",++c);

No cheating!


Ironically, if I ever got asked any of these questions at an interview with a company, I would walk out on the spot, unless they actually made developer tools.

Otherwise you are dealing with developers that make code complicated because 1) they can or 2) because they are actually bad developers and dont realize it yet. Either way, whatever projects they are working on are bound for failure or massive delays. Sadly, this mindset is far to common.

As to the OP, dont worry about it too much. As someone who has conducted a fair number of interviews in his lifetime, what the test you on often isnt that important, moreso they are interested in your thought process behind it. If you can illustrate that you are knowledgable about C++ but show lacking skills in C, if the company passes on you for that ( with, like you said, the company being a C++ company ), trust me, you arent missing out.

Just take what you know, be comfortable about it, and do the best you can. Dont over reach, just answer as best you understand, and if you dont... dont make shit up, it will only hurt you. That is, unless the company is looking for an idiot savant, which like I said earlier, if thats the case you dont want to work there.
Quote:Original post by Ozymandias42

1.) In what situation would you want to mark a variable "volatile const"?



When you want a constant that the optimizer won't remove (like when you want to edit it with a debugger).

This topic is closed to new replies.

Advertisement