If I am asked in an interview to write down some code, should I completely stick with C++ or is it acceptable to "mix" the two to write easy code as it comes to my mind?

I'll explain it: if I'm asked to create a "stack" data type, a C++ class is perfectly suited, while if I need to parse some strings a strtok/sscanf is far easier than STL. On the other hand, if I need a generic container STL and templates are the way to go.

Everything can be done in C or in C++, but in an interview I can't code everything or remember every standard/STL function. What is an acceptable tradeoff?

6 Answers
6

To be really pedantic, the C++ offers supports for C, natively, maybe only a subset, but if the topic is the C++ the C programming language is included, and this is not an opinion, i would expect no arguments on that in a professional environment.

Agreed. What's more, C is kinda part of C++ so why not use it to benefit? Sticking purely to one part of the language and not touching the other is not a good use of the language, in my opinion.
–
PiusAug 31 '12 at 5:17

Unless specified, most programming questions will let you use whatever language you want when answering a specific question. You may want to explain which language you are using to answer the specific question to avoid confusion and explain why you are using it.

If you are not sure if this will be OK with the interviewer, ask - it is absolutely acceptable to ask if you can answer different questions using different languages (in most on-paper answers, pseudo-code will be more than acceptable).

Yes, that's what I've been thinking: pseudo-code. I don't have a knowledge base in my mind and I tend to memorize techniques and way of using stuff rather than syntax or API declarations (which may change). If I can pseudo-code it and I have a "decent" amount of programming experience with a language, doesn't matter what it is I think I can code it.
–
John SmithAug 30 '12 at 19:30

2

It would be a positive sign in my book if the candidate was easily able to switch between C | C++ | C++ & STL and could explain why they chose a particular path.
–
GlenH7Aug 30 '12 at 19:32

6

@JohnPell - In my experience understanding principles and how and when to apply them trumps deep language knowledge every time.
–
Oded♦Aug 30 '12 at 19:33

You should just ask to the interviewer what he prefer, if you know how to use both.

Depending on his answer you can discover:

if he really know the differences between C and C++;

if he knows about C++ standard library;

if it's important to him.

There is no generic answer to this question. It's too dependent on the job and the objectives of the recruiter. If he wants you to show language knowledge then he will be specific. If he want you to show you problem solving skills, and communication skills, then he will not really care.

Unless your interviewer explicit request that you code in C or C++, I would just use what ever is appropriate for the interview.

For me, if my candidate was mixing the two up, I would be more interested in his strategy or reason for mixing the two language. Having someone on my team that can provide a solution and be able to justify the solution is extremely valuable.

If I am asked in an interview to write down some code, should I completely stick with C++ or is it acceptable to "mix" the two to write easy code as it comes to my mind?

That entirely depends on what kind of job you are applying for and which language they expect you to use. Generally, if you are writing C++, it is best to stick to C++ as far as possible. I would however expect every C++ programmer to know at least a bit of C (and vice versa).

I'll explain it: if I'm asked to create a "stack" data type, a C++ class is perfectly suited, while if I need to parse some strings a strtok/sscanf is far easier than STL. On the other hand, if I need a generic container STL and templates are the way to go.

If they expect you to write a whole working data type during the interview, you should be wary. It is good if they ask you about technical details, but if they expect you to spend hours of writing programs during the interview, that likely says something bad about the employer.

If you use scanf(), you have probably made a big mistake no matter if C or C++. You better explain to the interviewer that you are just writing something quick & dirty and would never use scanf in production code. There are many pit falls with various C library functions.

The interviewer shouldn't expect you to remember every function in the C and C++ standard librarier, but they should expect you to know which ones that are blatantly dangerous. gets(), getchar(), scanf(), setjmp() etc.

I think that when you are actually explicitly asked to do a short assignment in C++, it would be of utmost importance to actually stick with C++ and not mix C with it. Modern C is not a subset of modern C++, as such mixing the two would only imply that you aren't very familiar with what clean, modern C++ is like.