16

During an interview, I was asked whether I knew the difference between C and C++.

I was wondering why such question being asked?

Stella Lie
  • 189
  • 7
  • 11
    Given the number of C questions I've seen in just the last few weeks tagged C++ I'd say it was a pretty important question. – Gort the Robot Jun 10 '12 at 20:15
  • 13
    Judging by how often I see "C/C++", I'd say it's very common. – user16764 Jun 10 '12 at 20:15
  • 2
    @user16764: Modern, idiomatic C++ is very different from C, but it still (almost) contains C as a subset. – Giorgio Jun 10 '12 at 21:22
  • 6
    What did you answer? – Dima Jun 11 '12 at 03:42
  • I think its depends on which position do you apply, because its pretty strange for Java developer(without c/c++ experience ) to know those things... – artjom Jun 11 '12 at 07:09
  • 1
    "The difference" singular or "the differences" plural? It makes a big difference. – Peter Taylor Jun 11 '12 at 09:02
  • 8
    It's common for **an applicant** for programming job not to know anything at all. But I wouldn't call that person a programmer. – vartec Jun 11 '12 at 09:33
  • I know a few programmers who are self taught and don't know that there are 8 bits in a byte. – Tjaart Jun 11 '12 at 10:47
  • 6
    @Tjaart - You do understand there are systems where a byte isn't 8 bits right? – Ramhound Jun 11 '12 at 12:36
  • There are a *lot* of programmers who assume that because they know one, they automatically know the other, which of course isn't true. – John Bode Jun 11 '12 at 13:36
  • @Ramhound Its commonly accepted to be 8 bits. "The de facto standard of eight bits is a convenient power of two permitting the values 0 through 255 for one byte. With ISO/IEC 80000-13, this common meaning was codified in a formal standard." according to Wikipedia. A random answer for that question certainly would not indicate deeper knowledge. – Tjaart Jun 12 '12 at 11:45
  • It was for Java intern position. I answered the usual "C++ supports OO" and I think I won't be able to answer beyond that... – Stella Lie Jun 12 '12 at 16:46
  • They may have been trying to assess how much you know about things not on your resume. In other words, trying to figure out if you mess around on your own or just code for work and nothing more. It's very useful to be the sort of person who knows a little bit about everything in addition to knowing a lot about a few things. – Gort the Robot Jun 12 '12 at 19:35
  • @user16764: except you can't judge by how often you see "C/C++" -> http://programmers.stackexchange.com/questions/23760/languages-on-a-resume-is-it-better-to-put-c-c-or-c-c – haylem Jun 13 '12 at 04:04
  • 1
    @StellaLie: depends on much develop this answer. Any language can support OO, to some extent. What matters then is whether the runtime's implementation and the language's syntax provide the support and syntactic sugar to make it usable in such a way. You could very well do OO with C. – haylem Jun 13 '12 at 04:06
  • At least a programmer should know that C++ allows OO constructs (and more). – gsscoder Jun 13 '12 at 05:05
  • Wouldn't it depend on what kind of job your where going for? If it's (for example) developing Ruby On Rails then I wouldn't class it as relevant where as if it was for a C/C++ role then it would be much more pertinent. – Dan Diplo Jun 13 '12 at 07:36
  • 1
    (C - C++) == 0; – OldFart Jun 13 '12 at 15:23
  • 1
    @OldFart: If `C == INT_MIN`, then maybe not... – Thomas Eding Jun 13 '12 at 23:16

8 Answers8

41

Some people have observed that there's a huge amount of programming job applicants who can't write code at all. So, yes, asking "obvious" questions makes perfect sense.

Heinzi
  • 9,646
  • 3
  • 46
  • 59
  • 7
    This was going to pretty much be my answer. Having interviewed people for programming positions, I can tell you asking the obvious questions will cut out a good number of candidates very easily. – Tyanna Jun 10 '12 at 22:56
  • A million upvotes for you. I'm alawys amazed at the beginner level questions so many interviewees cannot answer. – HLGEM Jun 12 '12 at 17:10
  • 1
    Then again, I've been programming for over 25 years and there are some beginner-level questions I can't really answer anymore (gets worse if you ask for definitions). I was looking at the article linked in this answer and I was like "hmmm yeah let me think about that for a minute", whereas at work I work on implementing rather complex systems and generally don't have much trouble coming up with solutions. Some of those little questions scare me more than a multi-tiered system and throwing in some multithreaded functionality, crap like that... Weird, I know. – MetalMikester Jun 12 '12 at 17:39
  • 1
    indeed. As discussed on another P.SE thread, for interviews I've gotten into the habit of starting with ridiculously obvious questions ("how do you declare a variable in JS?", "how many bytes for 1 int in Java?", "what's a pointer?" etc...). I don't mind a first error (stress is a factor, even if I start interviews with conversations to relax them), but usually if I can get 3 strikes before reaching decent questions, then I consider it perfectly acceptable to hang up without going further or kick them out. The 5 minutes it takes to ask the stupid questions is worth the time saved. – haylem Jun 13 '12 at 04:14
  • 3
    In fact, I even **apologize** before asking these first questions, as I don't want skilled applicants to be weirded out by them, or think I'm not taking them seriously and to feel like they wouldn't belong here. – haylem Jun 13 '12 at 04:16
25

If the questions was phrased like "Do you know the difference between C and C++?" and you were allowed to just respond with "Yes" then I could see your confusion, but if they were actually asking "What -are- the differences between C and C++?" and a more open-ended answer was expected, I can see it as a legitimate "avenue of inquiry" as they say.

For example, only having ever coded in C and never in C++, I would barely be able to answer beyond a vague "C++ supports object oriented coding?".

Kzqai
  • 355
  • 2
  • 9
8

There's a whole bunch of them. There's an infinity of people who have idiot lecturers who teach C-strings and new and delete, or out-of-date tutorials or bad books, who learn "C++" but actually C, who think the two are pretty close.

Of course, if you're an employer, then saying that they're the same or even similar is a big warning light.

DeadMG
  • 36,794
  • 8
  • 70
  • 139
  • 2
    This brings up a very good point. It is acceptable and perhaps even common to teach C but use the C++ compiler. This of course leads to confusions by students who never learn the major differences betwen C and C++. I am only talking about the major differences between the same revision. – Ramhound Jun 11 '12 at 12:39
  • 4
    @Ramhound: It's not acceptable *at all*. The fact that it's common is orthogonal. – DeadMG Jun 11 '12 at 20:13
  • 2
    The sad fact is that C and C++ are almost universally taught badly. Go to SO and look through the C and C++ tags, and you'll see the same misconceptions, the same wrong interpretations, the same bad practices repeated over and over and over. These aren't people randomly making the same mistakes; they were *taught* how to make these mistakes. "My professor said..." is almost universally a red flag to me now. – John Bode Jun 13 '12 at 20:01
6

There are also a small percentage of people (such as myself) who learned C++ before they learned C.

I'm sure you know the differences, but if you are a student who has only had a C++ class, and not a C class the parts of C++ that are not C compatible will not be obvious.

Some of the more obvious differences I've learned (not an exhaustive list) () struct data types originally could not contain functions, and can't have private members, meaning it is very difficult to Enforce the validity rules of an abstract data type in C. () classes are not supported in C () passing by reference using the ampersand operator is specific to C++ () C doesn't support streams or templates (*) malloc and free are intended for use only in C and not in C++

A B
  • 386
  • 2
  • 5
  • 2
    I think this is a key insight... in the old days, you had a C compiler, then along came C++, so you learned the differences. Now you have C/C++ compilers and if you are taught C++ explicitly, it is well neigh impossible to know what is C and what is C++ beyond "the Object Oriented stuff" Also, I'm not sure C/C++ is the most common language to learn in anger(?) – Al Biglan Jun 12 '12 at 18:56
  • 1
    I'd very much hope the percentage is not as small, because those ["converted to C++" C programmers often are very bad C++ programmers](https://twitter.com/jaredpar/status/35468755307995136). – sbi Jun 13 '12 at 09:52
1

Unfortunately, I think it is becoming more and more common.

I think that young programmers freshly out of technical school (or where they learn their skills from) simply do not learn older languages such as C, C++, Lisp, OCaml, etc. They simply come out as "c# programmers" or "java programmers", etc. And when they find a job, they do not challenge themselves with learning other languages.

Of course there are some that do, but from those I have worked with, there is a general tendency for the younger programmers to follow this pattern.

Disclaimer: Since I am talking about education, then there can of course be differences from country to country about what is being emphasized in the education.

Pete
  • 8,916
  • 3
  • 41
  • 53
  • What universities are you talking about? "Arcane" languages? I had to learn assembly for MIPS at the university of Rome... – Vitaly Olegovitch Jun 11 '12 at 07:23
  • Generally, the "young" programmers I have met have had a degree in engineering. Come to think of it, almost all the programmers I work with have a degree in engineering, including myself. – Pete Jun 11 '12 at 07:49
  • 1
    C and C++ are still taught in school. The problem is most of the time the same compiler is used to teach both. This means they never actually learn the differences between the two languages. – Ramhound Jun 11 '12 at 12:40
  • @Pete If I came out as a 'C# programmer' I can't imagine going to learn C or C++ as 'another language'. Surely I'd like Ruby, Haskell, Javascript, Python. C-family languages are close enough that knowing one is enough. – Kirk Broadhurst Jun 12 '12 at 23:20
0

Answer

Yes, its common. I have seen this situation, either myself, coworkers, or third party libraries code.

Myself, for example, sometimes work with other programming languages or programming frameworks, and have to link, or update, to either "pure c" or "c++" libraries.

I just had the problem of modifying some "Pure C" code. And using "new" & "delete" memory allocation functions, that are "c++". The rest of the code was not object oriented

The compiler was C++. Later, I sued another compiler, and discovered the error.

Bonus

If some one ask, verbally, or in a written test, or web online test:

"Do you know the difference between C or C++"

And you answer "Yes" or "No".

They really mean:

"Do you know the difference between C or C++, if you do please tell me ?"

So, you have to answer:

"Yes. The difference its that C++ its Object Oriented, although, you may use Pure C, inside a C++ program, for backward compatibility."

Sometimes, they will not ask you "if you do please tell me", and they will assume that you don't know. Don't just answer "yes", or "no".

gnat
  • 21,442
  • 29
  • 112
  • 288
umlcat
  • 2,146
  • 11
  • 16
  • 2
    Well, I don't think that answer is entirely right. The right answer is that C++ has robust support for Object Oriented code. It does not require it. (Which is the source of this confusion in the first place.) – Gort the Robot Jun 12 '12 at 19:38
  • Also "you may use Pure C inside a C++ program" could mean something like "C++ is a superset of C, i.e. any C valid program is also a valid C++ program" (wrong). Or it might mean "you can link C++ programs to C libraries" (true, but most languages can link to C libraries some way or another.) You should be much more precise in an actual interview. – nikie Jun 12 '12 at 21:34
0

Probably not literally, in that they think C++ and C are one and the same, but in terms of truly understanding and being able to use the different features of C++, yes.

The main cause is the binary nature of listing languages / tools on your resume/CV. Essentially, the standard seems to be that if you got "Hello World" to compile and run in a language, than it is OK to list it on your resume/CV.

As it happens, the C version of "Hello, World!" also compiles and runs in C++. So, absent any other information, all that seeing "C++" on a resume tells me is that this person knows enough C to get "Hello, World!" running, and knows that most C programs will compile in C++.

Given that, I'm going to need to probe that a little bit on the interview. I probably wouldn't do so by asking a "Yes/No" "Do you know the difference?" question, in short because it has an obvious "right" answer. I would probably ask the candidate which language she liked better, why, and if there were any advantages to the one she didn't pick.

JohnMcG
  • 1,737
  • 9
  • 16
-2

Edit

As a foreward, note that this answer is not meant to declare that there are no differences or that I profess to know the differences, or even that I know than "Hello World" in either C or C++. It is an answer to the question by framing the terms of reference, pointing out that plenty of people know the elementary differences (e.g. one has some + characters in its name) and very few people will know all or even most of the differences.


It depends what you mean by 'programmer' and what you mean by 'difference'.

I'm a 'programmer' (although I call myself a developer) and I'd struggle to give any real differences between C and C++. If pressed I'd probably say that C++ is a superset of C that has namespaces and inheritence; different ways of dealing with memory. I know enough to patch some bugs or make some changes in your existing program but I can't imagine writing anything more than a simple utility in C or C++. I know enough to get by, but I don't paint myself as "knowing" either of those languages.

I know other 'programmers' (also developers) who wouldn't even tell you the difference between Java and FORTRAN, or Javascript and Pascal. They are good at what they do and they don't do procedural languages.

Then there are millions of mediocre programmers who barely know the single language they work with every day.

The term 'difference' is ambigious. I've pointed out what I see as some differences above, but I know they aren't definitive and complete. Very few people are going to know every difference - a lot more people are going to be able to give some vague answers (as I have) about object orientation.

Kirk Broadhurst
  • 4,199
  • 18
  • 27
  • 5
    "I'd struggle to give any real differences between C and C++." You're certainly not a C++ programmer. Please? – sbi Jun 13 '12 at 09:53
  • 2
    C and C++ are *vastly* different languages, coded in *vastly* different ways. You clearly just don't know them. – DeadMG Jun 13 '12 at 10:09
  • @sbi *"I don't paint myself as "knowing" either of those languages."* I'll let you decide that for yourself. – Kirk Broadhurst Jun 13 '12 at 22:56
  • Any feedback on the downvotes? Is it because I don't know the difference between the two? I wouldn't assume that would disqualify me from answering the question. – Kirk Broadhurst Jun 13 '12 at 23:04
  • @DeadMG I don't profess to know them, but I know that they are different. My answer points out that the question is too vague because there isn't just "the difference" between the two. – Kirk Broadhurst Jun 13 '12 at 23:14
  • 1
    @KirkBroadhurst: I think I indicated what part of your answer I disliked enough to downvote, and that comment was upvoted five times as often as you were downvoted after that, so I'm not sure what explanation you're after. However, to elaborate: The term "difference" is sufficient here, since C and C++ share only superficial syntactical similarities, and, other than that, are _very_ different languages. As for qualifications: I don't think there's a qualification needed to answer here, but when an answer is blatantly wrong as this one, it will be downvoted irrelevant of the qualification. – sbi Jun 14 '12 at 08:53
  • @sbi thanks for the feedback. As I've said above, I don't believe that one should need to know the difference between C and C++ to be able to answer the question. I've explained that I know what I (or many non C and C++ programmers) might consider 'the difference', but it's not what a C or C++ programmer would consider 'the difference'. This is a subjective, anecdotal question so I am not sure how an answer can be 'wrong'; my answer provides food for thought around the question; but of course you are free to downvote as you see fit. :) – Kirk Broadhurst Jun 14 '12 at 23:03