Sign in to follow this  
scottrick49

So I got through a phone interview...

Recommended Posts

Hi, I just graduated from college with a degree in CS and of course I want to get into game development. Yesturday I had a phone interview for a position as a game programmer, and now they want me to take a programming test. He said it would cover mostly C, but probably have one C++ question. Since I have done most of my projects thus far in C++, I am kind of wary about what kind of C questions they may ask. Any suggestions?

Share this post


Link to post
Share on other sites
my suggestion is don't worry. If you know C++ then you can pretty much do things in C, just drop the OOP paradigm (i.e. lose classes and everything involved with them, inheritence, etc.). Didn't they tell you that in school?

Share this post


Link to post
Share on other sites
If they know your experience is C++, it shouldn't be an issue. Just make sure and know malloc / free like the back of your hand. Short list of other things to keep in mind. printf / scanf line, no method overloading (use different function names), function pointers are extremely usefull in game programming.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
C has no classes, use structs instead

a struct is just like a class, except everything is public by default(you can switch it if you want, but why?)
and has no methods - you need to code separate functions that take the struct or ptr to the struct as an argument instead

C has no references, use pointers instead

all vars need to be declared at the beggining of a block before doing anything else

//slash slash style comments do not work, use /*asterisk style*/

by adding: extern "C" in front of a function declaration, you can make a C++ function that is callable from C code in a C compiler (the C++ function will need to be compiled to object file via the normal C++ compiler, and a C-safe header file is needed)

C is kinda a subset of C++, it is entirely possible to take C code and compile it with a C++ compiler just fine
the only thing to worry about is accidentally using C++ code in C compiler and having problems... but I don't think they are specifically trying to catch you on that kind of thing...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:

//slash slash style comments do not work, use /*asterisk style*/


Aren't double slash comments part of ANSI C, just not previous versions?

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:

//slash slash style comments do not work, use /*asterisk style*/


Aren't double slash comments part of ANSI C, just not previous versions?


If you mean C99, then you realize of course that Visual C++ is not C99 compliant. (It does of course support // for C files, but lacks nearly every C99 addition that is not part of C++).

Anyone using C for games is using C89 or a C/C++ hybrid. (Such as C89 with // comment support).

Share this post


Link to post
Share on other sites
I am terrified of coding tests as my mind has a tendancy to go blank at times like that.

I would rather they looked at the source code to my demo and examine how it is all structured and the design patterns used and the way I used the language in production code than test arbitary knowledge of various aspects of a programming language which can be looked up in a reference book in minutes.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Don't complicate things too much.

The C parts are probably just write a function that does 'x'.

The C++ part is probably write a class, template, etc that does 'x'.

I bet the test being in C doesn't necessarily mean its C specific, just no OO type stuff.

Still you should know the differences anyways.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I used to dislike tests too. But sometimes on the job, you gotta perform on the spot, whether you want to or not.

Plus tests start looking the same if you've taken enough of them :)

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
I hate questions like #3. They are retardedly pointless. Anyone writing code like that in production should be slapped.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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.[/quote]

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."

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Quote:
Original post by Serapth
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.


Okay, first, I don't believe that you're correctly using the word ironically, and second, would you really walk out in the middle of an interview with an othrewise great company simply because they asked you an obscure technical question?

Share this post


Link to post
Share on other sites
Academics love intricate syntax , most of them are pedant with syntax, and don't care about your problem solving capabilities, in the real world , everything is the contrary.

Share this post


Link to post
Share on other sites
would you really walk out in the middle of an interview with an othrewise great company simply because they asked you an obscure technical question?
No, I would walk out if I felt insulted or otherwise devalued. The interview is not just them interviewing me, but me interviewing a potential working environment. My standards are not unreasonable or even that strict and I can afford to walk out on interviews all day long. When you are placed at an interview by a placement agency, it's better to withdraw diplomatically to save face for the poor recruiter who has to deal with them daily and may provide future opportunities. Do not underestimate recruiters! Who cares what the employer pays or does not pay since you get interview experience FOR FREE :D

Share this post


Link to post
Share on other sites
Quote:
Original post by Jack9
would you really walk out in the middle of an interview with an othrewise great company simply because they asked you an obscure technical question?
No, I would walk out if I felt insulted or otherwise devalued. The interview is not just them interviewing me, but me interviewing a potential working environment. My standards are not unreasonable or even that strict and I can afford to walk out on interviews all day long. When you are placed at an interview by a placement agency, it's better to withdraw diplomatically to save face for the poor recruiter who has to deal with them daily and may provide future opportunities. Do not underestimate recruiters! Who cares what the employer pays or does not pay since you get interview experience FOR FREE :D


Well said.

I also suppose it depends on my situation. I havent interviewed for a job in years where I *needed* a job. If I was unemployeed, I might have a higher tolerance threshold. That said, yes an interview should be a two way process, if you are turned off a company before you even start there, you should take that as a sign and act accordingly. Plus, yes, I have walked out of a couple interviews, diplomatically of course. If I feel we are not a good fit, or something about the company bothers me, I will thank them for their time and excuse myself. In every case this has happenned, it was in a second ( or third ) interview when dealing with technical leads or division managers. Unlike the HR person that may screen you initially, these people are pretty representative of what the company will be like.

Share this post


Link to post
Share on other sites
Quote:

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.


Why?

"volatile const" is an interesting one, I think. It's uncommon, it would force the canidate to stop and think (hopefully). It's not difficult if you do that, and it might reveal something useful ("I don't understand the sum of the parts, but I understand its parts, perhaps I can make an educated guess about the functionality and seek confirmation" is useful). Note that for me, at least, an answer to this question could only earn you points. Unless you say, flat out, "I have no idea," without making an attempt to logic it out, I wouldn't dock you for arriving at the "wrong" answer.

The question about the ## operator is, I agree, rather unappealing.

The question about modifying a value more than once between sequence points is, I think, excellent. I've seen that mistake made far too many times by far too many programmers (professional or not). Although for this reason it wouldn't be a deal-breaker either. Unless the candidate was one of those pompous jerks claiming to "know all of C++" or some such.

I think you're making assumptions about the interviewer when you make claims about walking out (which doesn't, in my opinion, speak well of you). Interviewers don't always ask those kinds of questions because they write code that uses those examples in practice (I mean, hopefully they don't, especially the last!). They want to test your knowledge of the language, sure, but there is a lot more to it than that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this