I was wondering what are the differences between C and C++? I'm wondering because of the fact that I can follow along most C code and understand it. I know classes are new (and recently, namespace std) but what else?
Printable View
I was wondering what are the differences between C and C++? I'm wondering because of the fact that I can follow along most C code and understand it. I know classes are new (and recently, namespace std) but what else?
The STL, all kinds of little additions, I think new and delete are new to C++ or do they work in C?
new and delete as well as new[] and delete[] are specific for C++ and will not work in C, though malloc() and free() which are the equivalent in C (and are probably hidden somewhere in new and delete) will work in C++.
Structs in C++ work differently than in C. Inheritance and polymorphism are offshoots of classes and therefore not available in C.
C++ has templates.
They are very different from a design aspect. C focuses on procedural programming, while C++ focuses on object oriented and generic programming.
On a side note, C++ is not a superset of C.
The superset of C is "C with classes".
Structs are used differently (calling methods, ie you have to type struct before you create an object of a struct type)
Another thing C++ has is operator overloading
c
Code:malloc( )
printf( )
sprintf( )
fgets( )
char[ ]
free
int number = (int)'A' ;
c++
Code:new
cout
<<
cin
>>
string
delete
int number = static_cast<int>('A');
class { };
struct{ };
Why would you typecast a char into a char before assigning to an int??Quote:
Originally Posted by The Brain
oh my bad.. i'll edit
http://david.tribble.com/text/cdiffs.htmQuote:
Originally Posted by blankstare77
One is good and well the other is good :).