Between C and C++, which is easier to learn? Which is more powerful? Does either do anything special that the other doesn't?
thanks!
Between C and C++, which is easier to learn? Which is more powerful? Does either do anything special that the other doesn't?
thanks!
People write books on this subject but since it looks like you're new, I kept it simple :)
C++ makes it easier for a beginner to start doing useful things. However, it is by and large a superset of C. Also, many of the additional features are fairly complex. Thus, it's much easier to learn most of C than most of C++.
C is much smaller language, so it will be easier to learn the entire language.
C++ has some capabilities that make it easier (encapsulation, richer user defined types, etc). However, C++ also has some features that are better avoided (multiple inheritance), so if done wrong learning it could be a disaster.
Also the C++ language is so huge that I doubt there are many that know very nook and cranny of the language.
Accelerated C++ is a great way to learn C++. It avoids the darker corners and still teaches C++, as opposed to C with classes.
C++ is a little bit easier to learn at first, because you can do more powerful things with less code. But C is easier to master.
C is far easier to master, because it's a very small language. Some of the concepts (like pointers, aliasing, bit manipulation) are subtle, but you can master the syntax in a few months and never encounter a line of C code that you can't understand. The one exception is preprocessor macros - overuse of macros can make seemingly innocent C code do bizarre things.
C++ is almost impossible to master - the language is incredibly complicated, and there are dozens of obscure details that can get you into trouble. It can be very hard to read unfamiliar C++ code. Most large C++ projects have "style guides" and rules that disallow or restrict certain C++ features, to keep the project from getting too difficult to work with.
Your last question is, does either do anything special that the other doesn't. C++ is almost a perfect superset of C. That means that every C program is either already a C++ program, or with some trivial changes you can make it into a valid C++ program. This was by design. So C++ can do a lot of things that C can't.
There's only one thing that C can do that C++ can't: on most systems, C has a consistent, stable ABI. This means that two C libraries can talk to each other, no matter which version of C compiler they used. C++ program produced by different compiler versions often can't talk to each other. For this reason, C is used more often by very low-level libraries that need to be used throughout a system.
I actually find C to be easier, first, the standard is smaller, second there is "less to learn", and third, there's no way to suddenly be surprised by unfamiliar syntax when looking at code samples around the net. C has a smaller language footprint, less tokens have multiple context based meaning.
With that being said, between option A and option B, I choose option C...C# that is. The language is cleaner and makes worrying about memory management and reference types a little less confusing (although you still have to worry about them, it's much less troublesome for a new developer.) At the same time, you'll learn "Pure" Object oriented programming in a language that is still evolving. C# is one of the fastest growing languages, and the demand for .NET devs is starting to surpass that of C (but not C++) programmers.
My personal reccommendation however... Learn C, and then learn C#, or learn C#... and then learn C... Either way, once you know those two, learning C# takes just a few weeks and seems familiar.
My source? Me, 3 of my department co-workers, and a 2 hour discussion on this very topic around the office a few weeks ago, the devs that started With C seemed to have the most firm grasp on how code REALLY works, the devs that started with C++ leaned towards loose testing and "hacker" style coding, and the devs that started with C# usually had a really good grasp on "best practice." such as testing and design patterns. Either way, the C++ first programmers usually loathed learning anything else at first and fought against learning other languages simply because they were different. C# first programmers, usually didn't want to learn other languages, because they didn't feel that they'd have much to gain (tho i completely disagree) and C first programmers... learn it, realize how limited it is, and want to get away to something more expressive ASAP (C#/C++/Cyanide pills in their bosses's coffee, etc.)
Maybe not the answer you wanted, but I usually suggest new programmers start with python (www.python.org), then move (if appropriate) to another language when they have some idea what they want out of a language. Python is available for most platforms and is heavy duty enough to sustain large projects when needed.
If the choice is truly either C / C++ then by all means start with C. It's simpler and will serve as a springboard to C++ which you will ALSO want to learn. Both have advantages, and I choose which to use based on the project demands. Outside of pure systems programming / bit twiddling most folks I know find C++ a better choice for medium to large projects since it is object oriented. However there is LOTS of code still maintained in C even when it no longer really makes sense. (X-windows is my favorite example that I'd like to see re-written in C++)
Once you're comfortable with those languages I'd suggest you look also at go. (www.golang.org) It's a new language but I believe it will be a major player in the future. Go looks a lot like C but with some features to make concurrent programs easier to write. In other words, if you want to write programs that make the best use of that multi-core CPU you bought then you need to learn go.
Probably too long an answer. Sorry. :-)
Hotei
If you know some programming and know what object oriented programming stands for, then definitely go C++. By other hand, if you are new to programming and want to learn basic principles and algorithms, then try whit C.
Since you are new, go for C. It is simpler and you can keep most of language in your head. C++ is just to huge for beginner in my opinion.
C is a much smaller language and is, as a result, much easier to learn the fundamentals of. In comparison C++ is much, much, much, much larger and full of all kinds of sharp corners that can get you while you're learning. That being said, C++ is almost a superset of C, and you can start learning C++ by treating it as a "better C" and slathering on the other paradigms (object-oriented, declarative meta-programming, etc.) as you need them. Or you can, even better, start off with the simpler aspects of object-oriented programming and branch out into the other supported paradigms as you get more comfortable.
At their core, neither C nor C++ is "more powerful". They are both Turing complete and thus "equally powerful". What C++ is, however, is far more expressive. The language has many constructs built in that make some concepts easier to express and easier to comprehend than in C, although C could, in theory, do them as well.
One thing that puts C over C++ in terms of learning first, IMO, is that it is effectively the "lingua franca" of programming these days. Pick a programming language. Any programming language. Chances are very high that it has a FFI (foreign function interface) that's based on C. C is basically the "glue" language of the computing world these days, and the bridge, usually, between low-level programming and high-level programming languages. Further, there's also the issue of portability. I can't think of a modern environment that doesn't offer a C compiler (and very few older ones still in use which don't). I can think of dozens without C++ compilers, however, nor Java compilers nor any other of the "popular" languages. If you learn C you'll be able to get at least some programming done on practically any platform short of the tiniest of embedded systems (and even those will mostly have C compilers). C++ has nowhere near the saturation.
I think this is very debatable...
I personally thought that C was easier because there was no classes. But, learning about classes wasn't that much more to learn. Unfortunately, I was naive, and still am for that fact of the matter, and didn't realize there was a whole OOP methodology, that, because C has no classes, makes C++ a lot more difficult to master (I haven't mastered it yet either).
Also, what are you interested in? C++ is very good for making GUI (Graphical User Interfaces) with another library. Whereas, C is good for core development rather than graphics, because it is generally more efficient than C++.
Another point, once you learn C++ you have an easier transition to a lot of other languages because it OO. A lot of popular languages are OO languages and learning C++ gives you an easier transitions to those languages. Whereas, with C, you only get a view of procedural languages.
If your not in a rush why not learn the basics both? They are very similar, C++ is almost a strict superset of C (with a few exceptions). This way, you can learn about the differences. Also, when you learn both you realize that there are differences in the way approach programming with each since C is procedural and C++ is OO.
Yet if you are in a rush, chances are you probably should learn C++ even though it is slightly harder to learn the basics of because it opens up a lot of opportunities for beginners sooner.
Between C and C++, which is easier to learn?
C++ is completely compatible with C So for C++ there are more things to c.
Which is more powerful?
C++ has added features that can help you, but in terms of achieving something, Both are Equal,
Does either do anything special that the other doesn't?
C++ has many added features that if learnt properly can make your life easy.
So much debate. Blah blah blah. I'll make it simple for you:
Learn C++. Read this book first.
Between C and C++, which is easier to learn?
C is a reasonably compact language. If you have the kind of brain that can grasp the concept of pointers, you could learn C inside a month.
C++ is a monstrosity with truly enormous depth. It will take you years to become a C++ expert - and you will probably never truly master it.
Which is more powerful?
C++ is a superset of C. What C++ adds will allow you to do more while writing less code - I'd call that more "powerful".
Does either do anything special that the other doesn't?
C++ has a more well-equipped standard library, which has some very nice data structures and algorithms.
C on the other hand lacks the kind of facilities for doing "data structure stuff" easily and safely. If you want to be productive at writing any kind of non-trivial program - you want the "data structure stuff" ;)
C++ will merrily let you write C-style code. This is considered extremely poor form. And if you learn C before you learn C++ you'll be doubly at risk of doing this. Here is a good starting point of you want to write good C++ code (a very difficult thing).
Now that being said - learn C# (or python or something). From your own criteria: It's easier to learn, it's more powerful, and it does quite a few special things that C and C++ do not.
I think one point is to mention that all of these imperative, statically typed languages are semantically very similar indeed. In fact semantics is much more important than syntax when it comes to learning as IDEs will take care of much of that, plus compilers and debuggers.
The semantics of OOP are quite specific and since C isn't strictly OOP by any means, then C++, C# or Java are better as they support this. It's also much easier (I think) to build GUIs with these more modern languages.
Although C is the "smaller" language and C++ has this !!!HUGE BAG OF FEATURES!!! that so many here seem to find overwhelming, I would definitely say that C++ is going to be easier for a newb than C so long as you stay the hell away from the C part of the language.
You see, you can write C++ code that uses char*, char[], gets, fgets, etc... but everyone who knows C++ knows that you'd have to be freaking insane to want to. Why? Because of all the nasty bugs that live and breed there. You see, working with these types and functions is sort of like going out to a farm with a rifle to make a hamburger. In the end you might very well end up with a slightly leaner product but ALWAYS having to do all that gutting and skinning just gets really freaking old....so at some point you'll make a mistake.
And who in their right mind takes a new cook and hands them a rifle? No, first you hand them a prepackaged chunk of ground beef that's been processed by an expert butcher. This is what the C++ part of C++ is like. You know, the STL and all that...
Sure, at some point you're going to go into an expert cook's kitchen and see a spice you don't recognize. Here's the thing though...you don't have to use it. If you did learn you might make a better burger but if you're happy with what you're eating then you don't need to focus on the mass ratios of sea salt and table salt.
Of course, you have to learn from the right cook. Ted Nugent's cookbook isn't going to be the best for someone that doesn't own an arsenal of assault riffles...and a C++ book that starts out with scanf("%s",name)
is likewise absurd. Of course, someone else already linked you with the best beginner book out there, Accelerated C++.
Everyone of course knows that fire+gun+knife==food is much easier to remember than the 20 different packages you need to cook a hamburger like a modern, civilized human being but I prefer the later to the former most of the time and I definitely would consider it the easier path for those just learning to eat.
Everyone seems to be giving mostly an over-engineered answer.
The simple question was:
Between C and C++, which is easier to learn? Which is more powerful? Does either do anything special that the other doesn't?
The simple answer is:
C is easier to learn.
C and C++ are equally powerful languages, it all depends on what type of problems they are applied to.
C++ has a lot more special built-in constructs/abstractions that C, that is why C is easier to learn.
... more could be said but this covers your questions.
In order to avoid a lot of confusions it is best that you learn C first. Understand pointers very well and after you played a little in C (File I/O, some data structures: trees, [double-]linked lists, arrays) and you are confident you can start learning C++ in parallel. C is a very important language to understand because it will make it easier to understand problems that may appear in languages that are more evolved (C++ for example).
Learning C++ first it is easier but is has some disadvantages. Personally I knew a person who always used STL containers and was unable to debug a code with pointers written mostly in a C style. I believe that those persons shouldn't be considered programmers.
Enough talking, I say you learn C first (especially pointers). C++ will just work after that.