| Line 1: |
Line 1: |
| − | :''If you typed '''C#''' and arrived at this page, then see [[C-sharp]].'' | + | {{Infobox programming language |
| − | {{A-Z}} | + | | name = C++ |
| − | [[File:C cursiva.gif|thumb]] | + | | logo = File:ISO C++ Logo.svg |
| − | '''C''' is the third ([[three|3rd]]) [[letter]] in the [[English language|English]] [[alphabet]] and [[ISO basic Latin alphabet]].
| + | | paradigm = [[Multi-paradigm programming language|Multi-paradigm]]:<ref name="stroustruptcpppl" /> [[procedural programming|procedural]], [[functional programming|functional]], [[object-oriented programming|object-oriented]], [[generic programming|generic]] |
| − | == Meanings for C ==
| + | | year = 1983 |
| − | * In [[temperature]], ''°C'' means "degrees [[Celsius]]".
| + | | designer = [[Bjarne Stroustrup]] |
| − | * In [[music]], ''C'' is a [[Note (music)|note]] sometimes referred to as “Do”.
| + | | developer = Bjarne Stroustrup<br>[[Bell Labs]]<br>{{nobr|ISO/IEC JTC1/SC22/WG21}} |
| − | * In [[chemistry]], ''C'' is the atom of [[carbon]], as in '''C'''<sub>40</sub>[[H]]<sub>56</sub>.
| + | | latest_release_version = ISO/IEC 14882:2026 |
| − | * In [[physics]], ''c'' is the [[speed of light]], as in E=mc².
| + | | latest_release_date = {{Start date and age|2026|03|28|df=yes}} |
| − | * In [[Roman numeral]]s, ''C'' means "one [[hundred]]" (100).
| + | | latest_test_version = |
| − | * There is a [[programming language]] called ''C'', see [[C programming language]].
| + | | latest_test_date = |
| − | * In [[electronics]], C is a type of [[battery]].
| + | | typing = [[Static type|Static]], [[Type system#Safely and unsafely typed systems|unsafe]], [[Nominative type system|nominative]] |
| − | *C can also mean the [[copyright]] symbol
| + | | implementations = {{nowraplinks}}[[C++ Builder]], [[clang]], [[Comeau C/C++]], [[GNU Compiler Collection|GCC]], [[Intel C++ Compiler]], [[Microsoft Visual C++]], [[Sun Studio (software)|Sun Studio]]{{nowraplinks end}} |
| − | == Pronunciation == | + | | dialects = {{nowraplinks}}[[ISO/IEC 14882|ISO/IEC C++]] 1998, [[ISO/IEC 14882|ISO/IEC C++]] 2003, [[ISO/IEC 14882|ISO/IEC C++]] 2011, [[ISO/IEC 14882|ISO/IEC C++]] 2014, [[ISO/IEC 14882|ISO/IEC C++]] 2017, [[ISO/IEC 14882|ISO/IEC C++]] 2020{{nowraplinks end}} |
| − | *The letter "C" is pronounced as /k/, which is similar to K or Q(u). It is sometimes said as /s/.
| + | | influenced_by = [[C (programming language)|C]], [[Simula]], [[Ada (programming language)|Ada 83]], [[ALGOL 68]], [[CLU (programming language)|CLU]], [[ML (programming language)|ML]]<ref name="stroustruptcpppl">{{Cite book | last=Stroustrup | first=Bjarne | title=The C++ Programming Language | url=https://archive.org/details/cprogramminglang00stro_0 | year=1997 | edition=Third | <!-- chapter=1 | --> isbn=0201889544 | oclc=59193992 }}</ref> |
| − | *The letter "C"'s name in English is "cee" (said as /ˈsiː/).
| + | | influenced = [[Perl]]<!--1987-->, [[LPC (programming language)|LPC]]<!--1989-->, [[Lua]]<!--1993-->, [[Pike (programming language)|Pike]]<!-- 1994 -->, [[Ada (programming language)|Ada 95]]<!--1995-->, [[Java (programming language)|Java]]<!--1995-->, [[PHP]]<!--1995-->, [[D (programming language)|D]]<!--1999-->, [[C99]]<!--1999-->, [[C Sharp (programming language)|C#]]<!--2001-->, [[Falcon (programming language)|Falcon]]<!--2003--> |
| − | *Occasionally, the letter may sound like the letter "[[S]]".
| + | | operating_system = [[Cross-platform|Cross-platform (multi-platform)]] |
| | + | | license = |
| | + | | website = |
| | + | | file_ext = .h .hh .hpp .hxx {{nowrap|.h++}} .cc .cpp .cxx {{nowrap|.c++}} |
| | + | | wikibooks = C++ Programming |
| | + | |logo caption=C++ logo used by ISO}} |
| | + | [[File:BjarneStroustrup.jpg|right|thumb|<sub>Bjarne Stroustrup, the creator of C++</sub>]] |
| | + | '''C++''' ('''pronounced "c plus plus"''') is a [[computer]] [[programming language]] based on [[C programming language|C]]. It was created for writing computer programs. 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 similar, but different. |
| | | | |
| − | == C Media == | + | 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)|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 (programming)|templates]], "move semantics" and [[:en:Namespace#C++|namespaces]] (not full module support, while that was added later) and new [[operator overloading]] capabilities were added in versions C++11 and C++20. |
| − | <gallery widths='160px' heights='100%' mode='traditional' caption=''> | + | |
| − | File:Proto-semiticG-01.svg|# Proto-semitic Gimel, a theological invention.
| + | C++ runs on a most platforms (all mainstream ones), such as [[Windows]] and the various versions of [[UNIX]], such as [[macOS]], [[Linux]], and [[Berkeley Software Distribution|BSD]]. [https://web.archive.org/web/20200713161758/https://www.programstudio.online/2020/05/introduction-to-c.html 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 kinds of applications.<ref>{{Cite web|title=What is C++ Used For?|url=https://codinggrammar.com/what-is-cpp-used-for/|url-status=live|archive-url=https://web.archive.org/web/20200718094937/https://codinggrammar.com/what-is-cpp-used-for/|archive-date=2020-07-18}}</ref> |
| | + | |
| | + | [[:en:C++26|C++26]] is a major update, "C++26 has important memory safety improvements that you get just by recompiling your existing C++ code with no changes. .. At Google alone, it has already fixed over 1,000 bugs, is projected to prevent 1,000 to 2,000 bugs a year, and has reduced the [[:en:segmentation fault|segfault]] rate across the production fleet by 30%";<ref name = "cpp26_is_complete_herbsutter">{{cite web |last=Sutter |first=Herb |date=29 March 2026 |title=C++26 is done! — Trip report: March 2026 ISO C++ standards meeting (London Croydon, UK) |url=https://herbsutter.com/2026/03/29/c26-is-done-trip-report-march-2026-iso-c-standards-meeting-london-croydon-uk/ |website=herbsutter.com |location= |publisher= |access-date=29 March 2026}}</ref> thus [[:en:Herb Sutter|Herb Sutter]], calls C++26 is the most 'compelling' release since [[:en:C++11|C++11]]. |
| | + | |
| | + | C++26, from March 2026, is the latest version of the standard (no compiler has full support for it; Clang has partial support for it opting into with C++2c, GCC has experimental support in same way or with gnu++2c), C++23 the previous version, and C++20 the one before (GCC has almost full support for it and defaults to it in GCC 16; no compiler has full support), 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, or later, support the compilers may have. |
| | + | |
| | + | New C++ standards are on a three-year schedule, so the next one, likely C++29, is expected in 2029, 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 == |
| | + | The following text is C++ source code, and it will write the words "[[Hello world program|Hello World!]]" on the screen when it has been [[compiled language|compiled]] and is executed. Note it only works since C++23, since it's the new modern way to print in C++ (is done in a way much closer most other languages not diverging with the unusual older stream syntax): |
| | + | |
| | + | <syntaxhighlight lang="cpp" line="1"> |
| | + | import std; |
| | + | |
| | + | int main() { |
| | + | std::println("Hello, world!"); |
| | + | } |
| | + | </syntaxhighlight> |
| | + | |
| | + | The older way to print that still works (and will in future versions) and was typically the first program a programmer would write while learning about programming languages: |
| | + | |
| | + | <!-- |
| | + | C++ inherits most of [[C syntax|C's syntax]]. The following is Bjarne Stroustrup's version of the [[Hello world program]] that uses the [[C++ Standard Library]] stream facility to write a message to [[Standard output#Standard output (stdout)|standard output]]: |
| | + | |
| | + | This code is copied directly from Bjarne Stroustrup's errata page (p. 633). He addresses the use of <code>'\n'</code> rather than <code>std::endl</code>. Also see [http://www.stroustrup.com/bs_faq2.html#void-main Can I write "void main()"?] for an explanation of the implicit <code>return 0;</code> in the <code>main</code> function. This implicit return is ''not'' available in other functions. |
| | + | |
| | + | <syntaxhighlight lang="cpp" line="1"> |
| | + | |
| | + | *************************************************************** |
| | + | * |
| | + | * PLEASE NOTE: |
| | + | * |
| | + | * BEFORE MAKING CHANGES to the "Hello World" example |
| | + | * please establish consensus [..] |
| | + | * |
| | + | * The latest consensus is ''not'' to make any of those changes. |
| | + | * This is the example "Hello, world!" by Bjarne Stroustrup, |
| | + | * the author of the C++ language, and is used in |
| | + | * his book, "The C++ Programming Language (3rd edition)". |
| | + | * |
| | + | *************************************************************** |
| | + | --> |
| | + | <syntaxhighlight lang="cpp" line="1"> |
| | + | // 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> |
| | | | |
| − | File:Phoenician gimel.svg|Phoenician letter gimel
| + | // 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!"; |
| | + | } |
| | + | </syntaxhighlight> |
| | | | |
| − | File:Greek Gamma 03.svg|Glyph shape found in ancient Greek epigraphy (Gamma).
| + | This program is similar to the last, except it will add 3 + 2 and print the answer instead of "Hello World!". |
| | | | |
| − | File:Early Etruscan C.svg|Early Etruscan c
| + | <syntaxhighlight lang="cpp"> |
| | + | #include <iostream> |
| | | | |
| − | File:Copyright.svg|The copyright symbol drawn in SVG. Image version of the symbol ©.
| + | int main() |
| | + | { |
| | + | // Print a simple calculation. |
| | + | std::cout << 3 + 2; |
| | + | } |
| | + | </syntaxhighlight> |
| | | | |
| − | File:Phoenician gimel.svg|Phoenician letter gimel
| + | This program subtracts, multiplies, divides and then prints the answer on the screen. |
| | | | |
| − | File:Greek Gamma archaic 1.svg|One epigraphic letter shape of ancient Greek letter Gamma.
| + | <syntaxhighlight lang="cpp"> |
| | + | #include <iostream> |
| | | | |
| − | File:EtruscanC-01.svg|Etruscan H
| + | 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; |
| | | | |
| − | File:Old Latin G.svg|Old Latin letter G/C, created with Inkscape by using the PNG-Version as template.
| + | // Print calculations. |
| | + | std::cout << a-b-c; |
| | + | std::cout << a*b*c; |
| | + | std::cout << a/b/c; |
| | + | } |
| | + | </syntaxhighlight> |
| | + | == Manual memory management == |
| | + | C++ introduced two keywords <code>new</code> and <code>delete</code> 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 <code>new</code> and <code>delete</code> (and destructors) is no longer preferred in high-level code, rather containers such as <code>std:vector</code> (which at a low level are implemented with <code>new</code> and <code>delete</code>). |
| | | | |
| − | File:Capitalis monumentalis C.svg|Latin capital letter C in the style of the Roman Capitalis monumentalis, using the font Trajan Pro
| + | == C++ Media == |
| − | </gallery> | + | <gallery widths='160px' heights='100%' mode='traditional' caption=''> |
| − | == Other websites == | + | File:20160121 CppFRUG Joel Falcou CppQuiz 3.jpg|A quiz on C++11 features being given in Paris in 2015 |
| − | *{{wikt-inline}}
| |
| − | *{{commonscat-inline}}
| |
| | | | |
| − | {{Latin script}}
| + | File:C++ Standards Committee meeting - July 1996 Stockholm - Wednesday general session.jpg|Scene during the C++ standards committee meeting in Stockholm in 1996 |
| | | | |
| | + | File:ANSI ISO C++ WP.jpg|The draft "Working Paper" standard that became approved as C++98; half of its size was devoted to the C++ Standard Library. |
| | + | </gallery> |
| | + | == References == |
| | + | {{reflist}} |
| | | | |
| − | {{stub}} | + | {{authority control}} |
| | + | {{DEFAULTSORT:C}} |
| | + | [[Category:Multi-paradigm programming languages]] |
| | + | [[Category:Object-oriented programming languages]] |
| | + | [[Category:Cross-platform software]] |
| | + | [[Category:High-level programming languages]] |