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.

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. If you know C++, for a start, it's a piss-take to learn C, and secondly, it's really unimportant.
–
DeadMGAug 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.
–
KeithBAug 24 '10 at 16:23

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.

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.

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.

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

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.

@Alex Farber - "If you know C++, you can write in C". I highly doubt that :)
–
DumbCoderAug 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.
–
dan04Aug 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 FarberAug 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 DiblingAug 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."

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.

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.

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.

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.

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.

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.

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.

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.

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.. :)

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.