What's the relationship between C and C++?

I know a little bit of Python (for hobby programming purposes, nothing at professional level) and would now like to get into some compilable languages. C and C++ suggest themselves as popular options here. What’s the relationship like between those two? I understand that C is historically older and that C++ was developed later on as an extension; but I wonder what that means in practice. Is it fair to think of C++ as simply an extensive code library for C that adds more functions which are not available in basic C but follow the same general syntax and philosophy? Will any code written in C be handled correctly by a C++ compiler?

C++ is a much larger language that happens to include C.

The C in C++ is slightly, very slightly, different than the C in standard C, but not enough to make a difference most of the time. One of the c compilers I use is actually a c++ compiler, and the differences between c from different years are bigger.

Actually using c++ means using somebodies standard library. That requires understanding enough c++ that you don’t barf when looking at the code. It is possible to use c++ using only a tiny amount of the ++ stuff, but then you wouldn’t be using the libraries and then you wouldn’t be really using c++ in a useful way.

  chat_client(boost::asio::io_service& io_service,
      tcp::resolver::iterator endpoint_iterator)
    : io_service_(io_service),
    boost::asio::async_connect(socket_, endpoint_iterator,
        boost::bind(&chat_client::handle_connect, this,

Knowing c doesn’t help you with that.

c lacks any real way to logically group code and data (you’re forced to organize at the file level rather than the logical level), and the c++ objects provide this, so even if there is no structural reason why your code should be ‘object oriented’, c++ code is always written as objects.

Simple answer:

  • C is the original, a language with functions and data types. You can program in Python as if it is a more programmer-friendly kind of C
  • C++ is C extended with classes that provide a way to organize and extend functions and data types. The idea is that you thereby in effect modify the language to add your own kind of objects.

So it is really something beyond some new libraries.

I haven’t used either in a while so I’m sure there are far more difference these days, but I’m pretty sure the original idea was simply to have C++ be the object oriented version of C.

In the modern world, C++ is a vastly more featured language. C is a very stripped down and basic language with only basic operations and fundamental types. C++ was an attempt to create an object oriented language using C as a base. The early C++ system translated C++ into C, and you could write legal C in it. Neither are true anymore.

A bit of a rant.

Modern C++ is a huge mess of a language and eco-system. It is both a base language, and a set of extensions. And it is a moving target. You will find changes to the language and its eco-system over time render older code uncompilable. And new variants of the language has features that cannot be back ported to older code. The effort to use and maintain compatibility with C and its eco-system led to all manner of horrid compromises, some of which still taint and hobble C++.

IMHO (and I speak as someone who has coded a great deal in both C and older versions of C++) C++ is a language that should have strangled at birth. Even today it isn’t an OO language. You can still, 40 years later, create pointers ab-initio and manipulate pointers in code. There are add ons that provide all sorts of nice features, including automatic memory management. But you are not forced to use them. C++ users tend to adopt a personal subset of the language, and stick to that. And they adopt a subset of the various add-ons as well. This does not work well for proper software engineering practice. If you need to maintain C++ code, you have my sympathy. If you are writing a system from scratch, C++ is not the language to choose.

Speaking as someone who used to teach programming at university level, my personal feeling about languages worth using as teaching languages is to use Python and basic C. Python is nice is that it expresses what is going on in a clear manner. (C++ lies about that is going on under the hood.) Python has C bindings in a number of ways. This makes the pairing nice.
You can learn Python for its massive eco-system and expressive capacity. If you want, or need, to get your hands dirty getting close to the metal, use C. And you can neatly bind the two parts together.

Everyone gets wound up about Python being interpreted. Really, it just doesn’t matter. There is absolutely no intrinsic reason to choose compilation to machine code versus a byte-code as any sort of attribute of merit. It is elephants all the way down. Heck, have a play with Cython. That does compile to machine code. You may learn more faster using it. Inside the processor there are hidden mechanisms that are effectively interpreting the machine code. Much depends on the final target processor. But it wasn’t that long ago that x86 processors secretly translated x86 code into an internal RISC machine code.

Yes C++ is a completely different ball game. I wouldn’t recommend it to anyone as a good language to learn, especially if it’s only a hobby.

Perhaps you should look at a language with an integrated IDE that allows you to write proper Windows GUI applications. That would be far more interesting than low-level programming.

A while back I was in a somewhat similar situation:

C is pretty simple and you can easily learn it on your own. C++ is much more advanced. If you look into C++, it should probably be after you feel you are an accomplished programmer. In a way, the difference between C and C++ is like the difference between a Honda Civic and a Ferrari. Even though a Civic and a Ferrari are both cars, the added capability of a Ferrari comes from a ton more complexity and is
harder to drive and maintain.

One thing that’s different between C and C++ is that C++ adds object-oriented concepts. Python can also be object-oriented. That would be an easier way to learn those concepts since you’re already familiar with the language. Look around for “object oriented Python” and you’ll find lots of guides and tutorials. Getting over the object-oriented hurdle first in Python would mean that’s one less thing you’d have to learn in C++.

C++ is a superset of C with a lot of other stuff bolted on. If you want the advantages of design and organization offered by object-oriented programming, and you are already familiar with C, then you might choose C++. Java is also historically a popular choice for that case. It’s not a superset of either of those languages, but the syntax and concepts are very comparable.

If you’re just noodling around to try things on, C is a good exercise because it’s such a ubiquitous ancient workhorse, and so many other languages still rely on it under the hood. Plus it’s good to experience some of the stumbling blocks that have prompted the invention of other languages. But I don’t think I’d bother with C++ if I weren’t trying to leverage some existing expertise with C.

You might want to look at some modern non-object-oriented languages to see what they have to offer. I have been doing a lot of Elixir lately and I love it.

OP: If you provide more specifics of exactly what you want to do, posters here can provide advice as to what programming languages you might use.

Here is one index of the popularity of programming languages:


I was going to say something similar. Especially about the “strangled at birth” part.

Basically C is a straight-up procedural language. It’s pretty old-school, but it’s also very versatile and quick. And it’s closer to the hardware than pretty much anything other than assembly.

C++ is… well, like Seth Brundle from “The Fly” stuck C and an OO language in the pods, and out came C++. It’s not really object oriented, but you can more or less use it that way if you work at it. And you can do what a lot of us ended up doing in school; writing C code, but with some of the more handy C++ objects thrown in because the original C ones were pains in the ass to use. (the ones I remember clearly were using cin/cout rather than printf/scanf).

It was a revelation to go to graduate school about 5-6 years later, and learn JAVA; How easy and sensible that was by comparison with C++!

This is an important observation.

In the words of the ancient aphorism, “The C Programming Language — A language which combines the flexibility of assembly language with the power of assembly language.”

In addition to all the problems with c++ the language itself, the other problem is that it became the industry standard for Windows and events driven apps for many years.

This doesn’t sound like a problem, until you realize the language itself was ill suited to this, and the functionality was achieved through various badly designed APIs.

Put it this way: I worked as a c++ dev for about 8 years vs zero formal experience of Python. Yet if you want help with your Python code, i’m happy to help, whereas if you wanted help with c++ I’d be very hesitant, and would want to know what kind of code.

Fortran is at #13 and rising? :rofl:

However, popularity doesn’t really mean very much. It all depends what kind of programming you want to do.

If it’s web programming then Javascript and PHP, etc.

I would say (reluctantly) that probably Visual Studio VB .NET is a good option for a beginner wanting to play around. Reluctantly because I think .NET is cumbersome, and Visual Basic is not a serious professional language.

But it’s free, it’s object-oriented, it’s easy to learn, and it’s fun.

While I haven’t used either in a long time, VB.NET and C#.NET share the same underlying framework and classes, compile down to the same level, and even share runtimes. Since C# is considered to be (at least to my knowledge) a serious professional language, so I’m not sure why VB would be excluded.

As engineering students, we had a lot of programming courses. Assembly, Fortran, VHDL, C. I’ll never be ‘a programmer’ but I did ok in those classes. C++ had me and many of my classmates totally lost. Luckily, it was just a few weeks at the end of a course so we didn’t have to really master it or I’d have likely flunked.

People that remember Fortran from the days of Fortran-77 and programming with such horrors as common blocks and computed gotos would be amazed at what a modern Fortran looks like. For serious high performance numerical programming it would be close to the top of my list for a modern project. It isn’t your father’s Fortran.

Everything you say is true, but VB still has that kind of reputation. :slightly_smiling_face:

However, once you’re familiar with Visual Studio, it’s possible to switch over easily to any of the other languages it supports.

Oh, that I agree with. It’s wrong, but it absolutely exists.

Thanks. It was the first language I learned, back in the 1970s. I had to maintain some real spaghetti Fortran code in my time, but thankfully not for decades.