C++ is a general-purpose object-oriented programming (OOP) language, developed by Bjarne Stroustrup, and is an extension of the C language. It is therefore possible to code C++ in a "C style" or "object-oriented style." In certain scenarios, it can be coded in either way and is thus an effective example of a hybrid language.
C++ is considered to be an intermediate-level language, as it encapsulates both high- and low-level language features. Initially, the language was called "C with classes" as it had all the properties of the C language with an additional concept of "classes." However, it was renamed C++ in 1983.
C++ is one of the most popular languages primarily utilized with system/application software, drivers, client-server applications and embedded firmware.
The main highlight of C++ is a collection of predefined classes, which are data types that can be instantiated multiple times. The language also facilitates declaration of user-defined classes. Classes can further accommodate member functions to implement specific functionality. Multiple objects of a particular class can be defined to implement the functions within the class. Objects can be defined as instances created at run time. These classes can also be inherited by other new classes which take in the public and protected functionalities by default.
C++ includes several operators such as comparison, arithmetic, bit manipulation and logical operators. One of the most attractive features of C++ is that it enables the overloading of certain operators such as addition.
A few of the essential concepts within the C++ programming language include polymorphism, virtual and friend functions, templates, namespaces and pointers.
Suppliers C/C++ Development
Vendors C/C++ Development
F.A.Q. about C/C++ Development
Bjarne Stroustrup's FAQ
C is better than C++ for small projects, right?
Not in my opinion. I never saw a project for which C was better than C++ for any reason but the lack of a good C++ compiler.
Is C a subset of C++?
In the strict mathematical sense, C isn't a subset of C++. There are programs that are valid C but not valid C++ and even a few ways of writing code that has a different meaning in C and C++. However, C++ supports every programming technique supported by C. Every C program can be written in essentially the same way in C++ with the same run-time and space efficiency. It is not uncommon to be able to convert tens of thousands of lines of ANSI C to C-style C++ in a few hours. Thus, C++ is as much a superset of ANSI C as ANSI C is a superset of K&R C and much as ISO C++ is a superset of C++ as it existed in 1985.
What is the difference between C and C++?
C++ is a direct descendant of C that retains almost all of C as a subset. C++ provides stronger type checking than C and directly supports a wider range of programming styles than C. C++ is "a better C" in the sense that it supports the styles of programming done using C with better type checking and more notational support (without loss of efficiency). In the same sense, ANSI C is a better C than K&R C. In addition, C++ supports data abstraction, object-oriented programming, and generic programming (see my books).
I have never seen a program that could be expressed better in C than in C++ (and I don't think such a program could exist - every construct in C has an obvious C++ equivalent). However, there still exist a few environments where the support for C++ is so weak that there is an advantage to using C instead.
Do you really think that C and C++ could be merged into a single language?
I think that it would be a very good thing for the C/C++ community if they were. That is, if the C/C++ incompatibilities were systematically and completely eliminated and that future evolution was organized so as to prevent new incompatibilities from emerging. Whether that's possible is another matter.
My basic point is that the current C/C++ incompatibilities are "accidents of history" that have no fundamental reasons behind them (though they all "looked like a good idea at the time" to some competent and well-meaning people). The C/C++ incompatibilities provide no benefits to the community at large, cause serious problems to a large section of the C/C++ community, and could - with great difficulty - be eliminated.
For a far more detailed presentation of my views on C/C++ compatibility, see the series of papers I wrote about this:
- B. Stroustrup: C and C++: Case Studies in Compatibility. The C/C++ Users Journal. September 2002.
- B. Stroustrup: C and C++: A Case for Compatibility. The C/C++ Users Journal. August 2002.
- B. Stroustrup: C and C++: Siblings. The C/C++ Users Journal. July 2002.
- B. Stroustrup: Sibling rivalry: C and C++. AT&T Labs - Research Technical Report. TD-54MQZY. January 2002.
I imagine that if incompatibilities were eliminated (by making changes to both C and C++), there would still be entities called C and C++, but then C really would be defined as a subset of C++.
Why did you make C++ (almost) compatible with C?
I wanted C++ to be compatible with a complete language with sufficient performance and flexibility for even the most demanding systems programming.
At the time, I considered C the best systems programming language available. That was not as obvious then (1979) as it later became, but I had experts such as Dennis Ritchie, Steve Johnson, Sandy Fraser, Greg Chesson, Doug McIlroy, and Brian Kernighan down the corridor from whom I could learn and get feedback. Without their help and advice, and without C, C++ would have been stillborn.
Contrary to repeated rumors, I was never told that I had to use C; nor was I ever told not to use C. In fact, the first C++ manual grew from troff source of the C manual that Dennis gave me. Many new languages were designed at Bell labs; in "Research" at least, there were no rules enforcing language bigotry.
What do you think of C/C++?
No that's not really a question I often get. In that sense, it is the only "fake FAQ" in this FAQ. However, it ought to be a FAQ because people use "C/C++" as if it meant something specific and as if they knew what it meant, leading to much confusion and misery. People should ask "What is C/C++?" and then on reflection stop using the term. It does harm.
There is no language called "C/C++". The phrase is usually used by people who don't have a clue about programming (e.g. HR personnel and poor managers). Alternatively, it's used by people who simple do not know C++ (and often not C either). When used by programmers, it typically indicates a "C++ is C with a few useful and a lot of useless complicated features added" attitude. Often, that is the point of view of people who like to write their own strings and hash tables with little knowledge of the standard library beyond printf and memcpy. There are people who stick to a restricted subset of C++ for perfectly good reasons, but they (as far as I have noticed) are not the people who say "C/C++".
I use C/C++ only in phrases such as "C/C++ compatibility" and "C/C++ community".
When was C++ invented?
I started work on what became C++ in 1979. The initial version was called "C with Classes". The first version of C++ was used internally in AT&T in August 1983. The name "C++" was used late that year. The first commercial implementation was released October 1985 at the same time as the publication of the 1st edition of The C++ Programming Language. Templates and exception handling were included later in the 1980's and documented in The Annotated C++ Reference Manual and The C++ Programming Language (2rd Edition). The first ISO C++ standard was C++98 as described in The C++ Programming Language (3rd Edition).
The current definition of C++ The 2011 ISO C++ Standard described in The C++ Programming Language (4th Edition).
You can find a more complete timeline and more detailed explanations in The Design and Evolution of C++ and A History of C++: 1979-1991 and Evolving a language in and for the real world: C++ 19.