difference between c and c++

bag07l25

New Member
Messages
4
Reaction score
0
Points
0
hello, i want to know what the differnce between c and c++ is.
thank you
 

nullcity.dev91

New Member
Messages
47
Reaction score
0
Points
0
C++ is a extended form of C
and C is the original form of writing C.

example: C# is like VB.NET and C++ is for linux. Well, C is for all os.

additionally, you can add C++ support by using this:

#ifdef __cplusplus
extern "C" {
#endif

your c++ or c code goes here...

#ifdef __cplusplus
}
#endif
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
@bag07l25: what you've posted here doesn't seem to be a tutorial at all. Would you mind terribly reading the guidelines for the forum in the future? Thanks.

@nullcity.dev91: why do you tell lies? Most commercial Windows apps (and most of Windows, for that matter) were written in C++. C++ isn't "for Linux".

C has been described as "portable assembly language". It's a lot easier for a programmer to work with (both to write and to read) than binary, hex or mnemonic machine language coding, but it's still very "close to the metal". It's hard to get much of anything done if you don't understand addressing, pointers and byte packing, and if you don't understand something about how the underlying machine operates, at least at the level of abstraction the languages uses, you can quickly get into trouble. If you do understand the abstract machine, you can do magic -- having a program rewrite itself on the fly, for instance, to make things more efficient.

C++ is an "improved C" created and developed originally by Bjarne Stroustrup. (The "++" is the post increment operator in the C language. That means that the variable is "improved" after it is used in that part of the code. There has been much argument over the years over whether the name of the language constitutes a syntax error or not. Those who believe that C++ is an improvement think that it should have been named ++C; others, thinking that C++ is actually more suited to shooting yourself in the foot in much harder-to-understand ways, believe that the name is the correct one, and that the improved language will come along at the next call.)

Among other things, C++ is "C with classes". In C, you can create "structs" natively, which are data structures that are like a box full of stuff without instructions. Structs are good, in that you can package a whole bunch of data into a single variable and pass that package from place to place. They're bad in that every bit of code that touches a struct needs to have its own instruction manual. Including the instructions in the box is something that can only be done with a great deal of difficulty (meaning wild pointer stuff that nobody coming after you to maintain your code will be able to figure out). C++ natively includes the concept of classes and objects (instantiations of classes), along with all of the other object-oriented goodness we've come to know and develop a love-hate relationship with, like inheritance, encapsulation, polymorphism, and so on. What that means is that you can put the instructions in the box along with the data, so the code that deals with the box can be "stupider".

C++ also brings more predefined data types to the table, along with operator and function overloading, "//" single-line comments, exceptions (rather than just error codes), and a bunch of other things that were intended to make the programmer's life more pleasant. And most of it does what it says it's going to do -- for the original developer of a program, at least. It can be somewhat disconcerting for a maintenance developer to find out that "+" doesn't mean what he/she thought it did, and that the redefinition/overload happened in another file carefully included in a file that's included in a file that's included in a file (add about eight or ten more of these) that's included in the file he/she's working on.

Because it has first-class objects (so the rest of the code can be "stupider"), C++ is much easier to write large systems with than C. There are, however, lingering problems with C++ (and similar C variants), like the fact that memory is not automatically managed, that makes C++ an "expensive" language to work in, even if you carefully avoid features that can make the language itself a mess. That's why managed language environments, like Java and C#, are more popular in corporate environments -- it's much harder to create memory leaks or code that overwrites itself accidentally.
 
Top