C++

general-purpose programming language
(Redirected from C plus plus)


C++ (pronounced "c plus plus") is a computer programming language based on C. It was created for writing programs for many different purposes. In the 1990s, C++ became one of the most used programming languages in the world. Like C, C++ uses manual memory management (unlike most mainstream languages, where memory management is automatic), while the syntax usually used for it is different.

C++
C++ logo used by ISO
ParadigmMulti-paradigm:[1] procedural, functional, object-oriented, generic
Designed byBjarne Stroustrup
DeveloperBjarne Stroustrup
Bell Labs
ISO/IEC JTC1/SC22/WG21
First appeared1983
Stable releaseISO/IEC 14882:2020 / 15 December 2020; 4 years ago (2020-12-15)
Typing disciplineStatic, unsafe, nominative
OSCross-platform (multi-platform)
Filename extensions.h .hh .hpp .hxx .h++ .cc .cpp .cxx .c++
Websiteisocpp.org
Major implementations
C++ Builder, clang, Comeau C/C++, GCC, Intel C++ Compiler, Microsoft Visual C++, Sun Studio
Dialects
ISO/IEC C++ 1998, ISO/IEC C++ 2003, ISO/IEC C++ 2011, ISO/IEC C++ 2014, ISO/IEC C++ 2017, ISO/IEC C++ 2020
Influenced by
C, Simula, Ada 83, ALGOL 68, CLU, ML[1]
Influenced
Perl, LPC, Lua, Pike, Ada 95, Java, PHP, D, C99, C#, Falcon
Bjarne Stroustrup, the creator of C++

The C++ programming language was developed by Bjarne Stroustrup at Bell Labs in the 1980s, and was originally named "C with classes". The language was planned as an improvement on the C programming language, adding features based on object-oriented programming. Step by step, a lot of advanced features were added to the language, like exception handling, templates, "move semantics" and namespaces (not full module support, while that was added later) and new operator overloading capabilities were added in versions C++11 and C++20.

C++ runs on a most platforms (all mainstream ones), such as Windows, macOS, and the various versions of UNIX, for example Linux. Introduction to C++ language is a practical approach to describe the concepts of C++ for beginners to advanced software engineers.

C++ is a general-purpose programming language which means that it can be used to create many different kinds of applications.[2]

C++20 is the latest version of the standard, which finally added for example module support in December 2020 (while many languages supported modules a decade, if not two or more, earlier). The major compilers have almost complete support for C++20, while almost all default to the older C++17 standard, so a compiler switch is needed to enable the C++20 support the compilers have.

New C++ standards are on a three-year schedule, so the next one, C++23, is expected in 2023, and some compilers already have some (partial) support for that experimental standard. The many earlier C++ standards have each added stuff to the language, almost never taken stuff out, so mostly keeping compatibility with older standards.

Example

change

The following text is C++ source code and it will write the words "Hello World!" on the screen when it has been compiled and is executed. This program is typically the first program a programmer would write while learning about programming languages.

// This is a comment. It's for *people* to read, not computers. It's usually used to describe the program.

// Make the I/O standard library available for use in the program.
#include <iostream>

// We are now defining the main function; it is the function run when the program starts.
int main()
{
    // Printing a message to the screen using the standard output stream std::cout.
    std::cout << "Hello World!";
    return 0;
}

This program is similar to the last, except it will add 3 + 2 and print the answer instead of "Hello World!".

#include <iostream>

int main()
{
    // Print a simple calculation.
    std::cout << 3 + 2;
    return 0;
}

This program subtracts, multiplies, divides and then prints the answer on the screen.

#include <iostream>

int main()
{
    // Create and initialize three variables, a, b, and c, to 5, 10, and 20.
    int a = 5;
    int b = 10;
    int c = 20;

    // Print calculations.
    std::cout << a-b-c;
    std::cout << a*b*c;
    std::cout << a/b/c;
    return 0;
}

Manual memory management

change

C++ introduced two keywords new and delete for manual memory management (while also keeping compatibility with the old way C uses), and the constructor and destructor concepts. In modern C++ code, using new and delete (and destructors) is no longer preferred in high-level code, rather containers such as std:vector (which at a low level are implemented with new and delete).

References

change
  1. 1.0 1.1 Stroustrup, Bjarne (1997). The C++ Programming Language (Third ed.). ISBN 0201889544. OCLC 59193992.
  2. "What is C++ Used For?". Archived from the original on 2020-07-18.