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 have a question which I think can be best answered here.

I am pretty good with C++, good as in I am comfortable with the language, I have read Accelerated C++ and done almost all the exercises.

However, I have a big problem. Do I need to learn C? I have never done C ever in my life. I just started with C++ when I started with programming. Probably cause I was always interested in knowing why everyone calls the language so complex. Now though I know the answer to that question ;)

I am particularly interested in knowing whether I can survive without knowing C in today's world. Like if I give an interview in a company, if I tell them that I don't know C - will they take it as OK? The two languages I am good with is Python and C++. I am asking this cause I have heard that companies ask data structures in interviews. So if they ask me to implement it, and if I do it in C++, is it acceptable?

And people who say 'how can you not know C when you C++', please don't reply :) No offense, but I fail to understand why learning C is prerequisite.

share|improve this question

migrated from stackoverflow.com Jul 9 '11 at 10:49

This question came from our site for professional and enthusiast programmers.

closed as not constructive by Jeff Atwood Jul 9 '11 at 10:49

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
embeddedgurus.com/barr-code/2009/08/real-men-program-in-c Take your call. –  DumbCoder Aug 24 '10 at 13:36
1  
The article cited by DumbCoder is about the popularity of C in embedded programming. –  ChrisW Aug 24 '10 at 13:39
2  
@ChrisW - Yep, but it still shows C isn't that easy to master, not that C++ is easy to master. –  DumbCoder Aug 24 '10 at 13:41

16 Answers 16

up vote 36 down vote accepted

If you know C++, I wouldn't learn C just for the sake of it. You shouldn't find it too difficult to learn if and when you need it.

I'd far rather meet someone who claims they know C++ but not C than someone who claims they know C/C++.

share|improve this answer
17  
+1 for that "C/C++" (urban myths) :) –  Chubsdad Aug 24 '10 at 13:35
4  
+1. If you know C++, for a start, it's a piss-take to learn C, and secondly, it's really unimportant. –  DeadMG Aug 24 '10 at 13:49
5  
@DeadMG It might be easy to learn the syntax, since that is just knowing what parts of C++ to leave out, but learning the common idioms is harder, and arguably the most important part. BUt I wouldn't learn C unless needed. –  KeithB Aug 24 '10 at 16:23
5  
@chubsdad you mean I shouldn't put "I know Java/Javascript" on my CV? –  Incognito Aug 24 '10 at 18:38

Just my personal opinion: if you know C++, you can write in C. Some experience would be nice, but this is not a problem. The opposite is not correct: C knowledge doesn't allow to write in C++, without additional learning. I have never learn C, and use it when it is necessary, without any problems.

share|improve this answer
2  
@Alex Farber - "If you know C++, you can write in C". I highly doubt that :) –  DumbCoder Aug 24 '10 at 13:40
4  
Disagree. IME, programmers who learn C++ first tend not to realize what C++ features C doesn't have. Programmers who learn C first can easily write in C++, but start off non-idiomatically. –  dan04 Aug 24 '10 at 13:43
1  
This is based on my personal experience. I learned C++ and make most of my work in C++. But I use C when necessary, without any problems. –  Alex Farber Aug 24 '10 at 13:49
6  
C++ programmers trying to hack their way through C write bad code for the same reasons why C programmers trying to hack their way through C++ write bad code. The C guys use C++ as "C with classes" while the C++ guys use C as "C++ without classes." –  John Dibling Aug 24 '10 at 15:15

Okay, first things first - no, knowing C is not a prerequisite to learning C++. Indeed, it can be a hinderance.

Secondly, this is completely situational. Whether or not you'll need to know C depends entirely on whether the job requires it. If you want to be an embedded systems guy then yes, learning C will help. Otherwise, most jobs don't require it. If a job needs C it should say so. If it doesn't say so, it probably doesn't need it. In regards to the data structures, again it comes down to the company. Usually a company will say "We program in these languages, write us this data structure. Use the language of your choice from the list above." If they ask you to write it in C, you simply say "I don't know C - it doesn't say on my resume that I know C, this job isn't for me."

share|improve this answer

Like if I give an interview in a company, if I tell them that I don't know C - will they take it as OK?

Ask if they need C (and be willing to learn it or not if they do).

So if they ask me to implement it, and if I do it in C++, is it acceptable?

I would expect so, if they're interviewing/hiring you to work in C++.

If it's a "data structures" question, you might ask them whether they want you to demonstrate using STL containers, or whether (because it's an interview) they want you to implement the data structures from scratch.

share|improve this answer

I think if you are comfortable with C++ you will be too with C.

The main difference between the both is that C++ is clean - object oriented - C isn't :)

share|improve this answer

A very short answer to your question is: it depends highly on your needs. Some companies rely primarily on C, sometimes as a relic (if C had already been used for years there). Other companies do not have anything to do with C. C is a lower-level language than, say, Python or Java, and much application programming may not require any knowledge of C. Unlike OOP languages, C requires a different mindframe, by which I mean that programs are structured and organized differently, and some more nuanced aspects must be taken into consideration. It is generally beneficial to learn that idiom, even simply to expand your mind, so to speak. But again, whether companies will care depends on their needs. Some may give you a choice of language, some may require Java, others C++, other still C, etc. Can you survive? Yes - today's world has so many different areas of programming that you may never even pass by C code. Should you learn C? I'd say - yes, regardless of later use.

share|improve this answer

A multi-part answer. My opinions only.

  1. My experience (25 years out of college) is that C++, while increasingly uncommon, will continue to be vital to interesting systems for the foreseeable future. So I'm sticking with that as my main area of expertise. The work is hard, interesting and important.

  2. C++ programmers are generally valuable precisely because they have not grown up on managed languages, and so have more likelihood of understanding what's going on under the covers. It's easier to transition from C++ to C#/Java than vice versa because the bar for entry is higher.

  3. So while in my view, it's not essential to understand C in order to program competently in C++, developing an understanding of why C++ exists in the context of C - its limitations and its strengths and how they are addressed or not in C++ - would be invaluable to you over time.

Best of luck.

share|improve this answer
1  
+1 All valid points, well made. –  JBRWilkinson Aug 24 '10 at 14:23

If you're comfortable in C++ I wouldn't worry about learning C. C++ has a lot of improvements over C (the ability to support RAII with constructors/destructors, baseline containers, streams, and string are big).

I would however suggest learning the printf and scanf series of functions so you can READ code that uses them. They're quite popular in C++ so knowing how they're used is helpful. I don't suggest using them in your own code without a very specific reason.

share|improve this answer

Here is what Bjarne has to say:

Knowing C is a prerequisite for learning C++, right?

Wrong. The common subset of C and C++ is easier to learn than C. There will be less type errors to catch manually (the C++ type system is stricter and more expressive), fewer tricks to learn (C++ allows you to express more things without circumlocution), and better libraries available. The best initial subset of C++ to learn is not "all of C".

share|improve this answer

Some people may not feel comfortable programming in C while knowing C++.

There is a "protective" structure around C++ that contributes to drive not only the structure but also the algorithms of a program. For instance the help of the STL structure and algorithms, the obvious object oriented programming approach, the con/destructor, the added abstractive layer coming from the templates...

While C is - said - simpler, it forces the programmer to inject a structure and algorithms by himself into the problem modelization. This is an intense increase of programming freedom.
But it has a cost, as some people need more imposed structure, and build a program that tends to be exponentially harder to maintain as it gets bigger. I often say that the problem is not the language (C) but what one does with it.

This being said, as a recruiter, I'm glad to interview someone with strong C++ skills, but would be even more enthusiastic if she has enough language-autonomy to develop a whole C project.

Also, a good C program implies good developer system skills, as the language requires (usually) a fair understanding of the system components to build an efficient runnable.

share|improve this answer

Knowing C will give you further insights into memory management, etc.. It's all about how low-level you want to get, and whether understanding things at a lower lever helps you, or not. You could take it a step further and learn assembly language too, but it all depends how much it is worth to you.

It also depends whether you want to program in C or not. :)

share|improve this answer

The only time you need to know C is if you're expected to produce C code. If not, then there's no problem.

I haven't written C professionally in the last 6 years or so; there are plenty of application domains better served by other languages (at least from a productivity standpoint, if not performance) like Java or C# or Python. You most certainly can survive and even thrive as a software developer without ever touching C.

If you want to learn C for your own abusement, that's fine. Depending on how you learned C++ and how reliant you are on C++-specific features (templates, reference types, STL, overloading) you may flail a bit when you realize that 90% of the tools that made programming tolerable are no longer available. Stuff like memory management in C is very labor-intensive and tedious compared to C++ or Java. There are also some incompatibilities between C and C++, and with each new language version that gap is going to widen.

There are still application domains where C is the right tool for the job: small, fast, not much magic under the hood, and it's not assembly. But for general application development (especially GUI-driven desktop applications), there are far better tools available.

share|improve this answer

Yeah it's Ok...

IMHO, since you are good at C++, it is enough indeed...

I bet there are industries which are looking for C++ programmers... But once you are into it, it all depends on your project needs.. Whatever it requires you may have to learn.. It might be Java, .Net or even C.. If the company is ready to pay you, just learn it...

If you are in the earlier stages of your career, IME interviewers tend to look into your attitude and the understanding of the language that you are comfortable with..

Instead of learning C for the sake, learn C++ a bit thoroughly.. Improve on what you are good at.. I'm sure there's lot you may have to learn... For me, there's always something in C++ to learn.. :)

share|improve this answer

I think that the most important things for you to know regarding C is the differences between C and C++. You will likely see some code that has some C style in it at some point, and you should not be confused when you see things like malloc, free, printf, fopen, or fclose. You should also know how these are similar as well as how they are different from their C++ counterparts.

You should also know that << and >> are left and right shift operators, not insertion operators. In C++, where you can overload operators, these have been overloaded to perform stream insertion and similar things, but they are still used to shift integers.

Make sure you understand all of the basic features that C++ has that are not in C. If you read stackoverflow.com enough you will have seen many many questions that involve the differences in the languages and people's misunderstandings of them.

You should also familiarize yourself with the C preprocessor, which is almost the same as (and often the same program as) the C++ preprocessor. Knowing how to use it will help you in C++, but it is relied upon a lot more in C.

One big thing that is difficult to deal with in C that C++ has is destructors. Those things can be called all over the place taking care of resource freeing, but in C you have to do all of that more explicitly. This is easy for C++ programmers to forget about doing.

As far as interviews to, if someone asks you to write code for some general algorithm in C and you do something like:

struct foo {
       int a;
       void * b;
};
foo x;  // in C++ this would work, but in C it would fail because struct names aren't in the
        // type name table unless you put them there with typedef

I don't think that they are going to decide that you don't know what you are doing because you didn't do:

struct foo x;

And they really shouldn't care if you used cout unless what they are trying to get you to showcase is your ability to deal with input and output, which C++ makes easier for common cases.

If you do find yourself in the position of being interviewed for a job that requires C you should be upfront about your lack of knowledge of C outside of its overlap with C++. They will likely understand that a good programmer should be able to make the transition to C from C++ fairly quickly.

All of that being said, C is not that big of a language. The standard library is much smaller than C++'s and it isn't that big of a deal to familiarize yourself with the most common pieces of it, so it really can't hurt to learn it.

share|improve this answer

Do I need to learn C?

No, you do not need to. Period.

But learning any new programming language is beneficial in the long run. Learning languages based on different programming paradigms is even more beneficial. Whether it is an OOP language (Smalltalk or C++), a dynamic language (Lisp, Clojure, Python), functional (Lisp, Haskell, Erlang), concurrent (Erlang, Go, Algol 68, Smalltalk), or whatever (Fortran 03, Perl, Forth) other new fangled paradigm strikes your fancy; learning different languages helps exposure you to multiple lines of thinking, each with their own strengths and weaknesses for tackling the task at hand.

Fortran is still dominate in numeric computing, COBOL is still a mainstay at large insurance companies, Unix, BSD, and Linux are still based primarily on C. Old code doesn't lose its value with age always because it doesn't necessarily wear out like mechanical devices that need to be replaced over time. So older language can be valuable in terms of employability versus newer language's cool factor.

Just as studying to become multi-lingual in natural (human) languages arguably improves your ability to express yourself, the same carries the same sort of bonus for computer languages.

So while I do think it is important (over time) to learn to become fluent not only in multiple languages, but it is more important to be fluent in multiple programming paradigms.

I am pretty good with C++, good as in I am comfortable with the language, I have read Accelerated C++ and done almost all the exercises

I'm going to back up, and say that C++ is a rich and complex language, it will take years of exposure and constant practice to become truly fluent in all of its rich (or ugly) subtleties.

Take your time, and keep learning is the most important advice I can give you. For someone else's take on it, I encourage you to read Peter Norvig's Teach Yourself Programming in Ten Years.

share|improve this answer

C is almost a proper subset of C++. If you don't know C, then you don't know a big and important subset of C++. Do you have to learn this subset? No. C++ is a ridiculously big language and most people pick a subset and program with that. It's not required that you know the subset that is C. Especially, it is not as important to know the C standard library. However, I would cast a very suspicious eye toward anyone who did not understand core C concepts like pointers, arrays and bit twiddling.

share|improve this answer