|
The main difference between C and C++ is that C isn't object-oriented. Okay---that doesn't actually tell you what you want to know; here are some details:
+ structs don't copy in C. That is, if a and b are structs then the line a = b; doesn't work. Nor will structs be fed into functions as arguments. The only way to deal with them sensibly is to use pointers to them, or to write functions to copy their elements explicitly. classes (with private members) don't exist in C.
+ There is no operator and function overloading in C. If a function has a name, then that's it---you can't have another version with the same name that does the same thing with different arguments, as you can in C++. The fact that << and >> (left and right shift) do output and input in C++ is a consequence of the ability of the language to overload those operators. Output and input in C are handled by functions called printf and scanf respectively (these also work in C++ if you want, of course).
+ In C storage allocation and de-allocation are not handled by new and delete but by a function called malloc. In general, the whole process is a bit more messy in C, but is not too bad once you get the hang of it.
There are many more detailed differences, of course---see the books on the two languages for information on those. In general, C++ is neater and easier to read than C, and it does not compile to less efficient code as long as you know what you are doing. An example inefficiency here would be sending a large struct or class as a function argument by copying, as opposed to by reference using const X& fred (or whatever). The copying will eat stack space and waste time.
The only real reason for using C in preference to C++ is that the machine on which you wish to compile your program doesn't have a C++ compiler.
|