Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I know a bit of both C and C++. I am assuming that many people who know C++ also know C. I am wondering what language I should pick to code in during an interview.

C, because it's faster to make a working program in C, because you don't have to worry about thinking what objects your system should have, etc, as in C++ (though many experienced C++ programmers can code their solution in C++ in just the same amount of time)?

Or C++, because then you don't worry much about passing parameter by parameter and you can just pass around the object etc and you can leverage on existing string library, etc.?

share|improve this question
14  
"C? because it's faster to make a working program in C..." - Says who? –  Kevin Jun 4 '11 at 6:18
2  
Sounds like this is more about programming styles than languages. A more meaningful way to phrase your question would be "do you prefer to use big huge class hierarchies for interview coding questions". I can write very C-like code in C++, while taking advantage of, for example, C++'s bigger standard library to further simplify the task, but without writing a single class, if I feel designing a class is too much trouble. –  jalf Jun 4 '11 at 11:14
5  
I give python solutions if I must write on a board. –  Job Jun 4 '11 at 22:52
    
C implies fluent knowledge of pointers, do you really want to open that door? –  Jarrod Roberson Sep 1 '11 at 20:55

8 Answers 8

up vote 15 down vote accepted

The short answer is whichever one you know better. The longer answer depends on several factors.

  • Ask the interviewer if they are looking for the answer in a specific language.
  • Are you applying for a specific position? If so, what language requirement did the position list?
  • Is the question asked easier to implement in one language (that you are proficient with) than another?

Just as an aside, C is not the same as C++ and knowing one does not automatically make you proficient in the other (although it may help when learning), as CodeninjaTim has pointed out.

share|improve this answer
1  
+1 for "Ask the interviewer" Maybe they want to know that you can code it in a particular language. Maybe they don't care about your language choice. Or maybe they want to know which language you would choose in the real world, and they're hoping to screen out those that use Java or C++ for everything, even things where it's way easier in Perl/Python/Ruby. –  Eric Wilson Sep 1 '11 at 14:33

Well if its a case of C++ obviously the OOP concepts are showcased and in the case of C to get an fast working program and without much fuss u can strait away write the code and be able to visualize the flow easily.

share|improve this answer

Unless the interviewer asked for a specific language because they're testing my knowledge of that language, I always write in a vaguely C-like pseudocode. Because they often ask me to rough out a class/some classes I guess I'm writing C++ (or at any rate some C-like language with OOP), but for the most part the difference between these languages isn't relevant to anything I'd be doing on the whiteboard during an interview.

share|improve this answer

One thing I want to avoid is making silly mistakes, so I lean towards using C90 in interviews, because I know it cold (except for things I've decided not to memorize, like operator precedence). I don't know if this is really important, but personally I feel much more secure if I make sure I know everything about the language, and it's really, really difficult to know everything about C++.

share|improve this answer

If you are not applying for a very specific position (e.g: C++ software engineer), you are free to use the language you most feel comfortable with..

I had on-site interviews at Google as well and I used Java, Python and even pseudo-code, and coded both on sheets and board.

Don't waste time with language-specific issues: I can absolutely state that they are not interested in which programming language you'll be coding what they are asking you..Their interest is in how you handle problem-solving and analytical thinking (starting from the problem statement up to the code that best solves the question).

And don't be afraid if you don't write down the very perfect code on the fly! In fact, no one does...and Google knows, so they will appreciate iterative refinements on your code drafts!

share|improve this answer

I totally agree that you should always be using the programming language you feel most comfortable with. If I had to choose, I would choose C because, well, I do know some C++ but I wouldn't apply for a C++ only job if you know what I mean :)

C++ is extremely powerful and extremely complicated at the same time. Making a C++ program work can be a real struggle and a warpath through its nuances and pitfalls, unless you are EXTREMELY comfortable with it.

Andrea

share|improve this answer

I had my on-site interview with Google last week and they don't care what language you use. I used C unless I needed classes, but they actually suggested Python or JavaScript for some questions just to make them easier.

share|improve this answer
1  
+1 for practical example. –  intellidiot Jun 4 '11 at 12:26

You don't have to do one or the other. You can always write C style programs with classes used only when convenient.

share|improve this answer
6  
If someone did that in an interview it would definitely make me grill them more on how well they know C++, since a lot of people claim to know C++ without knowing much beyond "C with classes". I personally prefer C over C++, but IMHO, if you're going to write C++, then write idiomatic C++, instead of in a half-baked "C+" hybrid that has the worst features of both languages. –  Cercerilla Jun 4 '11 at 7:13
1  
True, but @whatsisname wasn't suggesting using "the worst features of both languages". It doesn't have to be "C with classes". It could be "C with a better standard library", or "C with a string class", or whichever ad-hoc hybrid makes sense for the particular constraints you're under (perhaps you're writing out the code on a whiteboard, in which case procedural code is often easier to write out than classes, or perhaps you're just under time pressure, and need to churn out some ugly but functional code in 2 minutes) –  jalf Jun 4 '11 at 11:19
3  
I agree with your point though (and I upvoted your comment). C and C++ are separate languages, and like you, I'd be very skeptical of a candidate who doesn't play to his "preferred" language's strengths. I wince when I see "C with classes", and if I'm hiring a C++ programmer, I definitely want to make sure that they actually know real modern C++, not just a bastardized C/C++ hybrid. –  jalf Jun 4 '11 at 11:21
1  
Most interview questions I've seen are small enough so code organization doesn't really matter. It's usually reasonable to use C++ as a "better C" in this case. However, make sure you follow through with it and are consistent. Don't use malloc or arrays or C-style string handling. If you do allocate memory, use a smart pointer. –  David Thornley Jun 7 '11 at 13:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.