bbguimaraes wrote:which means anything you can do in C, you can do in C++.
Not 100% accurate. There are quite a few little nuances between the two. Novice C and C++ developers may not be aware of them, but more advanced users of both languages definitely need to be familiar... It can be different enough that the C++ standard provides an
pragma.
bbguimaraes wrote:What C++ adds is two main programming paradigms: object-orientated programming and generic programming. Also, a standard library and a standard template library (a.k.a. STL).
C++ adds its OWN standard library, but C already has a standard library.
Benajmin100 wrote:I thought it was just that C didn't have classes and C++ did.
While there is definitely more to it than that, that's still a GIGANTIC difference. No polymorphism, encapsulation, or inheritance. That's an entire programming paradigm that the C language does not support natively (although you can still mimic each of these within the C language).
Benjamin100 wrote:I mean, why use C?
I will answer that by answering your next questions:
Benjamin100 wrote:Is C more efficient?
And if so, then why?
Yes. C code tends to be faster than the equivalent C++ code for a variety of reasons. Most of C++'s high-level object-oriented mechanisms have some sort of overhead associated with them. The most classic example is the vtable introduced by virtual functions. Each call to a virtual function requires a lookup table to invoke the correct "version" of the method depending on the type the object was instantiated as. When you get into some of the higher-level features of C++, especially the optional features, like exceptions and RTTI, you really start to introduce quite a bit more overhead.
There is also a shitload more overhead associated with an object-oriented mindset rather than with C++ as a language. Classes tend to have constructors, destructors, copy constructors, etc, whereas a structural paradigm in C uses straight initializers. C++ favors encapsulating the shit out of datatypes with additional "accessor methods" that provide function overhead that normally isn't present in C. There are plenty more examples of this, but I am currently high on hydrocodone, so I will stop here.
C is best suited for applications that are extremely low level and/or require very efficient resource management. It is most often used with microprocessors, drivers, and operating systems. All of these tasks would be a pain in the ass to write in C++, because of their low-level nature.
Many libraries and APIs tend to favor C over C++ for obvious compatibility reasons. A C library can be utilized by C or C++, but the reverse is not (easily) true. OpenGL, OpenAL, OpenCL, and SDL are great examples of this.
Benjamin100 wrote:Do you think I would benefit greatly in learning to use C?
Would it be easy after learning C++?
It depends on what you want to do. In the modern world, I think we are beginning to see the end of C's lifetime for your average desktop application. Languages like Java, C#, and C++ (with frameworks like QT) are going to be much better suited.
With that being said, the C language is still going to be king for a loooong time in the arenas of embedded systems, drivers, operating systems, and anything that is either extremely close to hardware or needs to be extremely fast.
Would YOU personally benefit from learning C? Probably not. But there are many people out there who honestly would. I work with the C language every day at work. I interface low-level C drivers for various chips with our C++-based embedded OS. It takes extensive knowledge of both languages and both programming paradigms. My hobbies are all either low-level game development related or are microprocessing related, where I am either writing C or am very closely interacting with it from C++.
Another interesting application of C that is emerging is using it as a wrapper language. Once I learned Objective-C, I thanked god almighty that I was well-versed in ANSI C. I was easily able to write minimal Obj-C and write the majority of my application(s) in C++. Then C++ and ObjC can communicate through a thin C wrapper. The same is becoming true for Java. Look at the NDK for Android. If you know what you're dong with C, you can get Java and C++ talking to each other...