I am familiar with java. but now i want to learn either of these. so which would be better to learn??
Depending on how familiar you are with Java (and programming in general), both should be relatively simple to pick up. All three are in the same family, after all. However, I suspect you'd find C++ more comfortable initially since it directly supports OOP.
I recomend you to learn C++11 directly. Learning C is the long way to C++98 to C++03 to C++11 and do not have any benefit. As a matter of fact, the style of programming and the way of think has evolved a lot. With C++11 there are many things you must forget from C++03 from C++98 form C. So jump directly to the best.
Note: There are a just new version called C++14 but it is only a very minor upgrade from C++11.
Learning C is the long way to C++98 to C++03 to C++11 and do not have any benefit.
You realize that C is more than just an intermediate step to C++, right?
So jump directly to the best.
Best is debatable. Since the OP didn't specify what context the languages would be used, it's incorrect to definitely say that C++ is better.
Deceptikon: Let me say that C is a very good language. I think it is the second best language that exist. As a matter of fact I have been programming in C a lot of years. However, C++ is a super set of C, so if you know C++ you know C. Also, you can compile "almost" any C program in a C++ compiler.
I think that the best language is C++. C++ is better than C because it has all that C has plus more. So, C++ at least can be as good as C but not less. However, if you need or want to use those other features, C++ is better. In this way any comparison between C and C++ goes in favor of C++.
Sorry if I gave the impression that C is more than just an intermediate step to C++. Probably I made this mistake because this is the way I learned C++. On the contrary, I believe that is better to learn C++ directly instead of learning C first and then C++, that is because the way of thinking in C++ is dramatically different to the way of thinking in C. I believe that it is a mistake to program in C++ “thinking” in C.
I think that C is “close to the machine” while C++, having all that has C, have many other things that sets the language “close to the problem to be solved”. The facilities added to C to create C++, such as function argument checking, const, classes, abstract data type with polymorphism, constructors and destructors, exceptions, templates, operator overloading and more; were primarily designed with the purpose that the concepts of a solution can be expressed directly and concisely.
C is a language that directly supports one style programming:
- PP: Procedural programming.
C++ features directly support four programming styles:
- PP: Procedural programming (like C), but also
- DA: Data abstraction,
- OO: Object-oriented programming, and
- GP: Generic programming.
However, the emphasis in C++ is on the support of effective combination of those. I don’t think that C++ is the best language because it allows to program in OO. I think C++ is the best because it allows to program in a very good balanced combination of all of those styles (or techniques).
Since the OP didn't specify what context the languages would be used, it's incorrect to definitely say that C++ is better.
I love OO but I don’t think that OO is the solution of all of the problems. So for the shake of this dialog, forget the OO technique but not the others. DA allows you to build libraries were you can write A=B+C to add two matrixes (for example) or two vectors (for another example) or two complex numbers (for even another example). With GP you can program a library like the STL were you can create containers with type checking, and also programs that are auto programmed during the compile time, all of this, beside of OO. Combining PP, DA, OO and GP you can build frameworks to create easily and fast, for example, games or even Operating Systems.
I don’t know if you want to compare only C with C++ or you want to include other languages. Including other languages will be a very impossible discussion because there exist to much languages and, obviously I only know a few of them. But comparing C with C++ is easy and I don’t think that it is possible to arrive a conclusion were C is better than C++. However, I am open and want to read about other opinions that you can express in favor of C against C++. Anyway, please, let me end this post with my first sentence: “C is a very good language”.
It seems like we largely agree. :)
However, C++ is a super set of C, so if you know C++ you know C.
C++ was originally a superset of C. Not so much nowadays, and especially when you pull in latest standards (C deviated from C++ with C99). I'm a strong proponent of the idea "if you know C++, you know C" being bullshit. Sure, you can write functional C, but good C takes a different mindset than good C++. Thus it's better to think of them as completely different languages.
Also, you can compile "almost" any C program in a C++ compiler.
After a fashion. ;) I'd wager that most C programs will fail to compile without minor changes. The first thing that comes to mind is adding a cast to
malloc calls, and it would be hard to find any serious C program that doesn't use
malloc. Note of course, that casting
malloc in C is a poor practice unless the code is intended to be cross-compilable with C++.
C++ is better than C because it has all that C has plus more.
More and better are not synonymous. Barring the train wreck of standardization beyond C95, one of my biggest likes about C is that it's so small yet so powerful.
Probably I made this mistake because this is the way I learned C++. On the contrary, I believe that is better to learn C++ directly instead of learning C first and then C++, that is because the way of thinking in C++ is dramatically different to the way of thinking in C. I believe that it is a mistake to program in C++ “thinking” in C.
I think a lot of us old C programmers learned that way. In the previous century, C++ was close enough to C that learning the C parts first was the go-to method of learning C++. Something I disagreed with even then, but it's understandable given that the teachers taught the same way they learned.
Fortunately, these days good teachers will teach using STL right out of the gate, which makes it easier to make good progress quickly without a lot of prerequisite knowledge in language features and computer science. Gone are the days where a C++ 101 project is "write a string class". ;)
I don’t think that it is possible to arrive a conclusion were C is better than C++.
In terms of widespread platform support, C++ is catching up to C, but C still wins out. I don't entirely disagree with you. Just putting that out there so nobody sees me as a stubborn C advocate. ;) However, I think there are still some gray areas in determining which language is the better choice for the situation. Typically the question arises when going very low level or for embedded platforms.
Yes, we largely agree!
In my previous post I didn't write the good things about C. Two of them that I can mention are the short time you need to learn it and the easy way to write a compiler for a new machine, neither a depreciable quality. As an old C programmer, I had been in love with C so my feelings can’t be changed easily.
But I want to say that if today I would be forced to return to program in C, it would be very difficult for me. It would be as difficult as forget my cellular and return to the time I must talk throw radio, CP1ADE (Charly Papa One Alpha Delta Eco) was my signal call :-)
I think that the best thing that might happen is the union between the ISO committees of C and C++. But for good or bad, it seems that that will never happen, isn’t it?
I appreciate your good comments. Thank you.
Edited by Maritimo
Look at any computer language as a toolbox. C++ has a lot more tools in the box than C.
C++11 adds a lot of cruft to the older versions of C++ that will leave newbies' brains in a fog. In any case, C++ works with C code just fine. Learn basic C++ and utilize exceptions to handle errors. Use C in your C++ code when you need to get closer to the hardware.
C++ has the Standard Template Library (STL) that makes your life so much easier when it comes to strings and vectors/arrays.
Also take a wiff of ...
Introduce yourself to classical OOP gradually, C++ allows this. A language that complements C++ very well is Python.
Edited by vegaseat