https://en.wikipedia.org/w/api.php?action=feedcontributions&feedformat=atom&user=C%2B%2B+Trolling+AlgorithmWikipedia - User contributions [en]2025-06-10T02:03:44ZUser contributionsMediaWiki 1.45.0-wmf.4https://en.wikipedia.org/w/index.php?title=Python_(programming_language)&diff=943900863Python (programming language)2020-03-04T14:20:54Z<p>C++ Trolling Algorithm: </p>
<hr />
<div>{{Other uses|Python (disambiguation){{!}}Python}}<br />
{{Short description|General-purpose, high-level programming language}}<br />
{{Use dmy dates |date=August 2015}}<br />
{{Infobox programming language<br />
| logo = Python logo and wordmark.svg<br />
| logo size = 250px<br />
| paradigm = [[Multi-paradigm programming language|Multi-paradigm]]: [[functional programming|functional]], [[imperative programming|imperative]], [[object-oriented programming|object-oriented]], [[reflective programming|reflective]]<br />
| released = {{start date and age|1990}}<ref name=guttag /><br />
| designer = [[Guido van Rossum]]<br />
| developer = [[Python Software Foundation]]<br />
| latest release version = 3.8.2<br />
| latest release date = {{Start date and age|2020|02|24|df=yes}}<ref>{{cite web |url=https://www.python.org/downloads/release/python-382/ |title=Python 3.8.2}}</ref><br />
| latest preview version = 3.9.0a4<br />
| latest preview date = {{Start date and age|2020|02|26|df=yes}}<ref>{{cite web |url=https://www.python.org/downloads/release/python-390a4/ |title=Python 3.9.0a4}}</ref><br />
| typing = [[duck typing|Duck]], [[dynamic typing|dynamic]], [[gradual typing|gradual]] (since 3.5)<ref>{{cite web|url=https://www.python.org/dev/peps/pep-0483/|title=PEP 483 -- The Theory of Type Hints|website=Python.org}}</ref><br />
| implementations = [[CPython]], [[PyPy]], [[Stackless Python]], [[MicroPython]], [[CircuitPython]], [[IronPython]], [[Jython]], [[RustPython]]<br />
| dialects = [[Cython]], [[RPython]], [[Bazel (software)|Starlark]]<ref>{{cite web|title=Starlark Language|url=https://docs.bazel.build/versions/master/skylark/language.html|accessdate=25 May 2019}}</ref><br />
| influenced = [[Apache Groovy]], [[Boo (programming language)|Boo]], [[Cobra (programming language)|Cobra]], [[CoffeeScript]],<ref>{{cite web |url=https://coffeescript.org/ |title=CoffeeScript borrows chained comparisons from Python}}</ref> [[D (programming language)|D]], [[F Sharp (programming language)|F#]], [[Genie (programming language)|Genie]],<ref>{{cite web <br />
|url=https://wiki.gnome.org/action/show/Projects/Genie<br />
|title=The Genie Programming Language Tutorial<br />
|accessdate=28 February 2020}}</ref> [[Go (programming language)|Go]], [[JavaScript]],<ref>{{cite web<br />
|title=Perl and Python influences in JavaScript<br />
|date=24 February 2013<br />
|website= www.2ality.com<br />
|url=http://www.2ality.com/2013/02/javascript-influences.html<br />
|accessdate= 15 May 2015}}</ref><ref>{{cite web<br />
|title=Chapter 3: The Nature of JavaScript; Influences<br />
|last=Rauschmayer<br />
|first=Axel<br />
|website=O'Reilly, Speaking JavaScript<br />
|url=http://speakingjs.com/es5/ch03.html<br />
|accessdate= 15 May 2015}}</ref> [[Julia (programming language)|Julia]],<ref name=Julia/> [[Nim (programming language)|Nim]], Ring,<ref name="The Ring programming language and other languages">{{cite web |url=http://ring-lang.sourceforge.net/doc1.6/introduction.html#ring-and-other-languages |title=Ring and other languages |author=Ring Team |date=4 December 2017 |work=ring-lang.net |publisher=[[ring-lang]]}}</ref> [[Ruby (programming language)|Ruby]],<ref name="bini"/> [[Swift (programming language)|Swift]]<ref name="lattner2014">{{cite web |url=http://nondot.org/sabre/ |title=Chris Lattner's Homepage |last=Lattner |first=Chris |date=3 June 2014 |accessdate=3 June 2014 |publisher=Chris Lattner|quote=The Swift language is the product of tireless effort from a team of language experts, documentation gurus, compiler optimization ninjas, and an incredibly important internal dogfooding group who provided feedback to help refine and battle-test ideas. Of course, it also greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list.}}</ref><br />
| license = [[Python Software Foundation License]]<br />
| website = {{URL|https://www.python.org/}}<br />
| wikibooks = Python Programming<br />
| influenced_by = [[ABC (programming language)|ABC]],<ref name="faq-created"/>, [[Ada (programming language)|Ada]] <ref>{{cite web | url=http://archive.adaic.com/standards/83lrm/html/lrm-11-03.html#11.3 | title=Ada 83 Reference Manual (raise statement)}}</ref>, [[ALGOL 68]],<ref name="98-interview"/> [[APL (programming language)|APL]],<ref name="python.org">{{cite web|url=https://docs.python.org/3/library/itertools.html|title=itertools — Functions creating iterators for efficient looping — Python 3.7.1 documentation|website=docs.python.org}}</ref> [[C (programming language)|C]],<ref name="AutoNT-1"/> [[C++]],<ref name="classmix"/> [[CLU (programming language)|CLU]],<ref name="effbot-call-by-object"/> [[Dylan (programming language)|Dylan]],<ref name="AutoNT-2"/> [[Haskell (programming language)|Haskell]],<ref name="AutoNT-3"/> [[Icon (programming language)|Icon]],<ref name="AutoNT-4"/> [[Java (programming language)|Java]],<ref name="AutoNT-5"/> [[Lisp (programming language)|Lisp]],<ref name="AutoNT-6"/> [[Modula-3]],<ref name="classmix" /> [[Perl]], [[Standard ML]]<ref name="python.org"/><br />
| file ext = .py, .pyi, .pyc, .pyd, .pyo (prior to 3.5),<ref>File extension .pyo was removed in Python 3.5. See [https://www.python.org/dev/peps/pep-0488/ PEP 0488]</ref> {{notatypo|.pyw}}, .pyz (since 3.5)<ref>{{cite web |url=https://www.python.org/dev/peps/pep-0441/ |last=Holth |first=Moore |date=30 March 2014 |accessdate=12 November 2015 |title=PEP 0441 -- Improving Python ZIP Application Support}}</ref><br />
}}<br />
<br />
A Python Program<br />
<br />
* x = 1<br />
* while x == 1:<br />
* print("Fuierdai Vandal")<br />
* print("Willy on Wheels")<br />
<br />
'''Python''' is an [[interpreted language|interpreted]], [[high-level programming language|high-level]], [[general-purpose programming language|general-purpose]] [[programming language]]. Created by [[Guido van Rossum]] and first released in 1991, Python's design philosophy emphasizes [[code readability]] with its notable use of [[Off-side rule|significant whitespace]]. Its language constructs and [[object-oriented programming|object-oriented]] approach aim to help programmers write clear, logical code for small and large-scale projects.<ref name="AutoNT-7" /><br />
<br />
Python is [[Dynamic programming language|dynamically typed]] and [[garbage collection (computer science)|garbage-collected]]. It supports multiple [[programming paradigms]], including [[procedural programming|procedural]], object-oriented, and [[functional programming]]. Python is often described as a "batteries included" language due to its comprehensive [[standard library]].<ref name="About" /><br />
<br />
Python was conceived in the late 1980s as a successor to the [[ABC (programming language)|ABC language]]. Python&nbsp;2.0, released in 2000, introduced features like [[list comprehension]]s and a [[garbage collection (computer science)|garbage collection]] system capable of collecting [[reference cycle]]s. Python&nbsp;3.0, released in 2008, was a major revision of the language that is not completely [[backward compatibility|backward-compatible]], and much Python&nbsp;2 code does not run unmodified on Python&nbsp;3.<br />
<br />
The Python&nbsp;2 language, i.e. Python 2.7.x, was officially discontinued on 1 January 2020 (first planned for 2015) after which security patches and other improvements will not be released for it.<ref>{{Cite web|url=https://www.python.org/doc/sunset-python-2/|title=Sunsetting Python 2|website=Python.org|language=en|access-date=2019-09-22}}</ref><ref>{{Cite web|url=https://www.python.org/dev/peps/pep-0373/|title=PEP 373 -- Python 2.7 Release Schedule|website=Python.org|language=en|access-date=2019-09-22}}</ref> With Python 2's [[end-of-life (product)|end-of-life]], only <!-- shortened for the lead: Python&nbsp;3.7.x and later will be supported,<ref>{{Cite web|url=https://www.python.org/dev/peps/pep-0537/|title=PEP 537 -- Python 3.7 Release Schedule|website=Python.org|language=en|access-date=2019-11-06}}</ref> plus 3.5.x<ref>{{Cite web|url=https://www.python.org/downloads/release/python-359/|title=Python Release Python 3.5.9|quote=Python 3.5 has now entered "security fixes only" mode, and as such the only changes since Python 3.5.4 are security fixes.|website=Python.org|language=en|access-date=2019-11-06}}</ref><ref>{{Cite web|url=https://www.python.org/downloads/release/python-3410/|title=Python Release Python 3.4.10|quote=Python 3.4 has reached end-of-life.|website=Python.org|language=en|access-date=2019-11-06}}</ref> and 3.6.x with security updates only (and [[source code|source]]s only).<ref>{{Cite web|url=https://www.python.org/dev/peps/pep-0494/|title=PEP 494 -- Python 3.6 Release Schedule|website=Python.org|language=en|access-date=2019-11-06}}</ref><ref>{{Cite web|url=https://www.python.org/downloads/release/python-369/|title=Python Release Python 3.6.9|website=Python.org|language=en|access-date=2019-11-06}}</ref> --> Python&nbsp;3.5.x<ref>{{Cite web|url=https://devguide.python.org/#status-of-python-branches|title=Python Developer’s Guide — Python Developer's Guide|website=devguide.python.org|access-date=2019-12-17}}</ref> and later are supported.<br />
<br />
Python [[interpreter (computing)|interpreters]] are available for many [[operating system]]s. A global community of programmers develops and maintains [[CPython]], an [[open-source software|open source]]<ref>{{cite web |url=https://docs.python.org/3/license.html |title=History and License |accessdate=5 December 2016}} "All Python releases are Open Source"</ref> [[reference implementation]]. A [[nonprofit organization|non-profit organization]], the [[Python Software Foundation]], manages and directs resources for Python and CPython development.<br />
<br />
== History ==<br />
[[File:Guido van Rossum OSCON 2006 cropped.png|thumb|150px|[[Guido van Rossum]] at OSCON 2006]]<br />
<br />
{{Main|History of Python}}<br />
<br />
Python was conceived in the late 1980s<ref name="venners-interview-pt-1" /> by [[Guido van Rossum]] at [[Centrum Wiskunde & Informatica]] (CWI) in the [[Netherlands]] as a successor to the [[ABC (programming language)|ABC language]] (itself inspired by [[SETL]]),<ref name="AutoNT-12" /> capable of [[exception handling]] and interfacing with the [[Amoeba (operating system)|Amoeba]] operating system.<ref name="faq-created" /> Its implementation began in December 1989.<ref name="timeline-of-python" /> Van Rossum shouldered sole responsibility for the project, as the lead developer, until 12 July 2018, when he announced his "permanent vacation" from his responsibilities as Python's ''[[Benevolent Dictator For Life]]'', a title the Python community bestowed upon him to reflect his long-term commitment as the project's chief decision-maker.<ref name="lj-bdfl-resignation" /> He now shares his leadership as a member of a five-person steering council.<ref>{{cite web |title=Guido van Rossum Stepping Down from Role as Python's Benevolent Dictator For Life {{!}} Linux Journal |url=https://www.linuxjournal.com/content/guido-van-rossum-stepping-down-role-pythons-benevolent-dictator-life |website=www.linuxjournal.com |language=en}}</ref><ref>{{cite news |title=Python boss Guido van Rossum steps down after 30 years |url=https://www.theinquirer.net/inquirer/news/3035842/python-boss-guido-van-rossum-steps-down-after-30-years |newspaper=[[The Inquirer]]|language=en}}</ref><ref>{{cite web |title=PEP 8100 |url=https://www.python.org/dev/peps/pep-8100/ |website=python |publisher=Python Software Foundation |accessdate=4 May 2019}}</ref> In January 2019, active Python core developers elected Brett Cannon, Nick Coghlan, Barry Warsaw, Carol Willing and Van Rossum to a five-member "Steering Council" to lead the project.<ref>{{cite web |title=PEP 8100 |url=https://www.python.org/dev/peps/pep-8100/ |publisher=Python Software Foundation |accessdate=4 May 2019}}</ref><br />
<br />
Python 2.0 was released on 16 October 2000 with many major new features, including a [[Cycle detection|cycle-detecting]] [[garbage collection (computer science)|garbage collector]] and support for [[Unicode]].<ref name="newin-2.0" /><br />
<br />
Python 3.0 was released on 3 December 2008. It was a major revision of the language that is not completely [[backward compatibility|backward-compatible]].<ref name="3.0-release" /> Many of its major features were [[backporting|backported]] to Python 2.6.x<ref name="pep-3000" /> and 2.7.x version series. Releases of Python 3 include the <code>2to3</code> utility, which automates (at least partially) the translation of Python 2 code to Python 3.<ref>{{cite web |url=https://docs.python.org/3/library/2to3.html |title=Automated Python 2 to 3 code translation — Python Documentation |accessdate=11 February 2018 }}</ref><br />
<br />
Python 2.7's [[end-of-life (product)|end-of-life]] date was initially set at 2015 then postponed to 2020 out of concern that a large body of existing code could not easily be forward-ported to Python 3.<ref>{{cite web |url=https://legacy.python.org/dev/peps/pep-0373/ |title=PEP 373 -- Python 2.7 Release Schedule |work=python.org |accessdate=9 January 2017}}</ref><ref>{{cite web |url=https://www.python.org/dev/peps/pep-0466/ |title=PEP 466 -- Network Security Enhancements for Python 2.7.x |work=python.org |accessdate=9 January 2017}}</ref><br />
<br />
== Features and philosophy ==<br />
Python is a [[multi-paradigm programming language]]. [[Object-oriented programming]] and [[structured programming]] are fully supported, and many of its features support [[functional programming]] and [[aspect-oriented programming]] (including by [[metaprogramming]]<ref name="AutoNT-13" /> and [[metaobject]]s (magic methods)).<ref name="AutoNT-14" /> Many other paradigms are supported via extensions, including [[design by contract]]<ref name="AutoNT-15" /><ref name="AutoNT-16" /> and [[logic programming]].<ref name="AutoNT-17" /><br />
<br />
Python uses [[dynamic typing]] and a combination of [[reference counting]] and a cycle-detecting garbage collector for [[memory management]]. It also features dynamic [[Name resolution (programming languages)|name resolution]] ([[late binding]]), which binds method and variable names during program execution.<br />
<br />
Python's design offers some support for [[functional programming]] in the [[Lisp (programming language)|Lisp]] tradition. It has <code>filter</code>, <code>map</code>, and <code>reduce</code> functions; [[list comprehension]]s, [[Associative array|dictionaries]], sets, and [[generator (computer programming)|generator]] expressions.<ref name="AutoNT-59"/> The standard library has two modules (itertools and functools) that implement functional tools borrowed from [[Haskell (programming language)|Haskell]] and [[Standard ML]].<ref name="AutoNT-18" /><br />
<br />
The language's core philosophy is summarized in the document ''The [[Zen of Python]]'' (''PEP 20''), which includes [[aphorism]]s such as:<ref name="PEP20" /><br />
<br />
<!-- Note this isn't a full list, just some of the more significant aphorisms --><br />
* Beautiful is better than ugly.<br />
* Explicit is better than implicit.<br />
* Simple is better than complex.<br />
* Complex is better than complicated.<br />
* Readability counts.<br />
<br />
Rather than having all of its functionality built into its core, Python was designed to be highly [[Extensibility|extensible]]. This compact modularity has made it particularly popular as a means of adding programmable interfaces to existing applications. Van Rossum's vision of a small core language with a large standard library and easily extensible interpreter stemmed from his frustrations with [[ABC (programming language)|ABC]], which espoused the opposite approach.<ref name="venners-interview-pt-1" /><br />
<br />
Python strives for a simpler, less-cluttered syntax and grammar while giving developers a choice in their coding methodology. In contrast to [[Perl]]'s "[[there is more than one way to do it]]" motto, Python embraces a "there should be one—and preferably only one—obvious way to do it" design philosophy.<ref name="PEP20" /> [[Alex Martelli]], a Fellow at the Python Software Foundation and Python book author, writes that "To describe something as 'clever' is ''not'' considered a compliment in the Python culture."<ref name="AutoNT-19" /><br />
<br />
Python's developers strive to avoid [[premature optimization]], and reject patches to non-critical parts of the [[CPython]] reference implementation that would offer marginal increases in speed at the cost of clarity.<ref name="AutoNT-20" /> When speed is important, a Python programmer can move time-critical functions to extension modules written in languages such as C, or use [[PyPy]], a [[just-in-time compilation|just-in-time compiler]]. [[Cython]] is also available, which translates a Python script into C and makes direct C-level API calls into the Python interpreter.<br />
<br />
An important goal of Python's developers is keeping it fun to use. This is reflected in the language's name—a tribute to the British comedy group [[Monty Python]]<ref name="AutoNT-24"/>—and in occasionally playful approaches to tutorials and reference materials, such as examples that refer to spam and eggs (from a [[Spam (Monty Python)|famous Monty Python sketch]]) instead of the standard [[Foobar|foo and bar]].<ref>{{cite web |url=https://insidetech.monster.com/training/articles/8114-15-ways-python-is-a-powerful-force-on-the-web |title=15 Ways Python Is a Powerful Force on the Web}}</ref><ref>{{cite web |url=https://docs.python.org/2/library/pprint.html |title=pprint - Data pretty printer - Python Documentation}}</ref><br />
<br />
A common [[neologism]] in the Python community is ''pythonic'', which can have a wide range of meanings related to program style. To say that code is pythonic is to say that it uses Python idioms well, that it is natural or shows fluency in the language, that it conforms with Python's minimalist philosophy and emphasis on readability. In contrast, code that is difficult to understand or reads like a rough transcription from another programming language is called ''unpythonic''.<br />
<br />
Users and admirers of Python, especially those considered knowledgeable or experienced, are often referred to as ''Pythonistas''.<ref name="AutoNT-27" /><ref name="AutoNT-25" /><br />
<br />
== Syntax and semantics ==<br />
{{Main|Python syntax and semantics}}<br />
<br />
Python is meant to be an easily readable language. Its formatting is visually uncluttered, and it often uses English keywords where other languages use punctuation. Unlike many other languages, it does not use [[curly bracket programming language|curly brackets]] to delimit blocks, and semicolons after statements are optional. It has fewer syntactic exceptions and special cases than [[C (programming language)|C]] or [[Pascal (programming language)|Pascal]].<ref name="AutoNT-52" /><br />
<br />
=== Indentation ===<br />
{{Main|Python syntax and semantics#Indentation}}<br />
<br />
Python uses [[whitespace character|whitespace]] indentation, rather than [[curly bracket programming language|curly brackets]] or keywords, to delimit [[block (programming)|blocks]]. An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.<ref name="AutoNT-53" /> Thus, the program's visual structure accurately represents the program's semantic structure.<ref name=guttag>{{Cite book| publisher = MIT Press| isbn = 978-0-262-52962-4| last = Guttag| first = John V.| title = Introduction to Computation and Programming Using Python: With Application to Understanding Data| date = 2016-08-12}}</ref> This feature is sometimes termed the [[off-side rule]], which some other languages share, but in most languages indentation doesn't have any semantic meaning.<br />
<br />
=== Statements and control flow ===<br />
Python's [[Statement (computer science)|statements]] include (among others):<br />
<br />
* The assignment statement (token '=', the equals sign). This operates differently than in traditional [[imperative programming]] languages, and this fundamental mechanism (including the nature of Python's version of ''variables'') illuminates many other features of the language. Assignment in [[C (programming language)|C]], e.g., <code>x = 2</code>, translates to "typed variable name {{var|x}} receives a copy of numeric value 2". The (right-hand) value is copied into an [[Memory allocation|allocated storage location]] for which the (left-hand) [[Variable (computer science)|variable name]] is the symbolic address. The memory allocated to the variable is large enough (potentially quite large) for the declared [[Type system|type]]. In the simplest case of Python assignment, using the same example, <code>x = 2</code>, translates to "(generic) name x receives a [[Pointer (computer programming)|reference]] to a separate, dynamically allocated [[Object (computer science)|object]] of numeric (int) type of value 2." This is termed ''binding'' the name to the object. Since the name's storage location doesn't ''contain'' the indicated value, it is improper to call it a ''variable''. Names may be subsequently rebound at any time to objects of greatly varying types, including strings, procedures, complex objects with data and methods, etc. Successive assignments of a common value to multiple names, e.g., <code>x = 2</code>; <code>y = 2</code>; <code>z = 2</code> result in allocating storage to (at most) three names and one numeric object, to which all three names are bound. Since a name is a generic reference holder it is unreasonable to associate a fixed [[Type system|data type]] with it. However at a given time a name will be bound to ''some'' object, which '''will''' have a type; thus there is [[Dynamic type|dynamic typing]].<br />
* The <code>[[if-then-else|if]]</code> statement, which conditionally executes a block of code, along with <code>else</code> and <code>elif</code> (a contraction of else-if).<br />
* The <code>[[Foreach#Python|for]]</code> statement, which iterates over an iterable object, capturing each element to a local variable for use by the attached block.<br />
* The <code>[[While loop#Python|while]]</code> statement, which executes a block of code as long as its condition is true.<br />
* The <code>[[Exception handling syntax#Python|try]]</code> statement, which allows exceptions raised in its attached code block to be caught and handled by <code>except</code> clauses; it also ensures that clean-up code in a <code>finally</code> block will always be run regardless of how the block exits.<br />
* The <code>raise</code> statement, used to raise a specified exception or re-raise a caught exception.<br />
* The <code>class</code> statement, which executes a block of code and attaches its local namespace to a [[class (computer science)|class]], for use in [[object-oriented programming]].<br />
* The <code>def</code> statement, which defines a [[function (computing)|function]] or [[method (computing)|method]].<br />
* The <code>with</code> statement, from Python 2.5 released in September 2006,<ref>{{cite web|url=https://www.python.org/download/releases/2.5/|title=Python 2.5 Release|website=Python.org}}</ref> which encloses a code block within a context manager (for example, acquiring a [[lock (computer science)|lock]] before the block of code is run and releasing the lock afterwards, or opening a [[Computer file|file]] and then closing it), allowing [[resource acquisition is initialization|Resource Acquisition Is Initialization]] (RAII)-like behavior and replaces a common try/finally idiom.<ref>{{cite web|url=https://www.python.org/download/releases/2.5/highlights/|title=Highlights: Python 2.5|website=Python.org}}</ref><br />
*The [[break statement|<code>break</code>]] statement, exits from the loop.<br />
*The <code>continue</code> statement, skips this iteration and continues with the next item.<br />
* The <code>pass</code> statement, which serves as a [[NOP (code)|NOP]]. It is syntactically needed to create an empty code block.<br />
* The <code>[[assertion (programming)|assert]]</code> statement, used during debugging to check for conditions that ought to apply.<br />
* The <code>yield</code> statement, which returns a value from a [[generator (computer programming)#Python|generator]] function. From Python 2.5, <code>yield</code> is also an operator. This form is used to implement [[coroutine]]s.<br />
* The <code>import</code> statement, which is used to import modules whose functions or variables can be used in the current program. There are three ways of using import: <code>import <module name> [as <alias>]</code> or <code>from <module name> import *</code> or <code>from <module name> import <definition 1> [as <alias 1>], <definition 2> [as <alias 2>], ...</code>.<br />
* The <code>print</code> statement was changed to the <code>print()</code> function in Python 3.<br />
<br />
Python does not support [[tail call]] optimization or [[first-class continuations]], and, according to Guido van Rossum, it never will.<ref name="AutoNT-55" /><ref name="AutoNT-56" /> However, better support for [[coroutine]]-like functionality is provided in 2.5, by extending Python's [[generator (computer programming)|generators]].<ref name="AutoNT-57" /> Before 2.5, generators were [[lazy evaluation|lazy]] [[iterator]]s; information was passed unidirectionally out of the generator. From Python 2.5, it is possible to pass information back into a generator function, and from Python 3.3, the information can be passed through multiple stack levels.<ref name="AutoNT-58" /><br />
<br />
=== Expressions ===<br />
Some Python [[Expression (computer science)|expressions]] are similar to languages such as [[C (programming language)|C]] and [[Java (programming language)|Java]], while some are not:<br />
<br />
* Addition, subtraction, and multiplication are the same, but the behavior of division differs. There are two types of divisions in Python. They are floor division (or integer division) <code>//</code> and floating point<code>/</code>division.<ref>{{cite web|title=division|url=https://docs.python.org|website=python.org}}</ref> Python also added the <code>**</code> operator for exponentiation.<br />
* From Python 3.5, the new <code>@</code> infix operator was introduced. It is intended to be used by libraries such as [[NumPy]] for [[matrix multiplication]].<ref name=PEP465>{{cite web |title=PEP 0465 -- A dedicated infix operator for matrix multiplication |url=https://www.python.org/dev/peps/pep-0465/|website=python.org |accessdate=1 January 2016}}</ref><ref name=Python3.5Changelog>{{cite web |title=Python 3.5.1 Release and Changelog |url=https://www.python.org/downloads/release/python-351/|website=python.org |accessdate=1 January 2016}}</ref><br />
* From Python 3.8, the syntax <code>:=</code>, called the 'walrus operator' was introduced. It assigns values to variables as part of a larger expression.<ref name=Python3.8Changelog>{{cite web |title=What’s New In Python 3.8 |url=https://docs.python.org/3.8/whatsnew/3.8.html |accessdate=14 October 2019}}</ref><br />
* In Python, <code>==</code> compares by value, versus Java, which compares numerics by value<ref>{{cite web |url=https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.21.1 |title=Chapter 15. Expressions - 15.21.1. Numerical Equality Operators == and != |publisher=[[Oracle Corporation]] |accessdate=28 August 2016}}</ref> and objects by reference.<ref>{{cite web |url=https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.21.3 |title=Chapter 15. Expressions - 15.21.3. Reference Equality Operators == and != |publisher=Oracle Corporation |accessdate=28 August 2016}}</ref> (Value comparisons in Java on objects can be performed with the <code>equals()</code> method.) Python's <code>is</code> operator may be used to compare object identities (comparison by reference). In Python, comparisons may be chained, for example <code>a <= b <= c</code>.<br />
* Python uses the words <code>and</code>, <code>or</code>, <code>not</code> for its boolean operators rather than the symbolic <code>&&</code>, <code>||</code>, <code>!</code> used in Java and C.<br />
* Python has a type of expression termed a ''[[list comprehension#Python|list comprehension]]''. Python 2.4 extended list comprehensions into a more general expression termed a ''[[generator (computer programming)|generator]] expression''.<ref name="AutoNT-59" /><br />
* [[Anonymous function]]s are implemented using [[Lambda (programming)|lambda expressions]]; however, these are limited in that the body can only be one expression.<br />
* Conditional expressions in Python are written as <code>x if c else y</code><ref name="AutoNT-60" /> (different in order of operands from the <code>[[?:|c ? x : y]]</code> operator common to many other languages).<br />
* Python makes a distinction between [[list (computer science)|lists]] and [[tuple]]s. Lists are written as <code>[1, 2, 3]</code>, are mutable, and cannot be used as the keys of dictionaries (dictionary keys must be [[immutable]] in Python). Tuples are written as <code>(1, 2, 3)</code>, are immutable and thus can be used as the keys of dictionaries, provided all elements of the tuple are immutable. The <code>+</code> operator can be used to concatenate two tuples, which does not directly modify their contents, but rather produces a new tuple containing the elements of both provided tuples. Thus, given the variable <code>t</code> initially equal to <code>(1, 2, 3)</code>, executing <code>t = t + (4, 5)</code> first evaluates <code>t + (4, 5)</code>, which yields <code>(1, 2, 3, 4, 5)</code>, which is then assigned back to <code>t</code>, thereby effectively "modifying the contents" of <code>t</code>, while conforming to the immutable nature of tuple objects. Parentheses are optional for tuples in unambiguous contexts.<ref>{{cite web|title=4. Built-in Types &#8212; Python 3.6.3rc1 documentation|url=https://docs.python.org/3/library/stdtypes.html#tuple|website=python.org|accessdate=1 October 2017}}</ref> <br />
* Python features ''sequence unpacking'' wherein multiple expressions, each evaluating to anything that can be assigned to (a variable, a writable property, etc.), are associated in the identical manner to that forming tuple literals and, as a whole, are put on the left hand side of the equal sign in an assignment statement. The statement expects an ''iterable'' object on the right hand side of the equal sign that produces the same number of values as the provided writable expressions when iterated through, and will iterate through it, assigning each of the produced values to the corresponding expression on the left.<ref>{{cite web|title=5.3. Tuples and Sequences &#8212; Python 3.7.1rc2 documentation|url=https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences|website=python.org|accessdate=17 October 2018}}</ref> <br />
* Python has a "string format" operator <code>%</code>. This functions analogous to <code>[[printf format string|printf]]</code> format strings in [[C (programming language)|C]], e.g. <code>"spam=%s eggs=%d" % ("blah", 2)</code> evaluates to <code>"spam=blah eggs=2"</code>. In Python 3 and 2.6+, this was supplemented by the <code>format()</code> method of the <code>str</code> class, e.g. <code>"spam={0} eggs={1}".format("blah", 2)</code>. Python 3.6 added "f-strings": <code>blah = "blah"; eggs = 2; f'spam={blah} eggs={eggs}'</code>.<ref name="pep-0498">{{cite web |title=PEP 498 -- Literal String Interpolation |url=https://www.python.org/dev/peps/pep-0498/|website=python.org |accessdate=8 March 2017}}</ref><br />
* Python has various kinds of [[string literal]]s:<br />
** Strings delimited by single or double quote marks. Unlike in [[Unix shell]]s, [[Perl]] and Perl-influenced languages, single quote marks and double quote marks function identically. Both kinds of string use the backslash (<code>\</code>) as an [[escape character]]. [[String interpolation]] became available in Python 3.6 as "formatted string literals".<ref name="pep-0498"/><br />
** Triple-quoted strings, which begin and end with a series of three single or double quote marks. They may span multiple lines and function like [[here document]]s in shells, Perl and [[Ruby (programming language)|Ruby]].<br />
** [[Raw string]] varieties, denoted by prefixing the string literal with an <code>r</code>. Escape sequences are not interpreted; hence raw strings are useful where literal backslashes are common, such as [[regular expression]]s and [[Microsoft Windows|Windows]]-style paths. Compare "<code>@</code>-quoting" in [[C Sharp (programming language)|C#]].<br />
* Python has [[array index]] and [[array slicing]] expressions on lists, denoted as <code>a[key]</code>, <code>a[start:stop]</code> or <code>a[start:stop:step]</code>. Indexes are [[zero-based]], and negative indexes are relative to the end. Slices take elements from the ''start'' index up to, but not including, the ''stop'' index. The third slice parameter, called ''step'' or ''stride'', allows elements to be skipped and reversed. Slice indexes may be omitted, for example <code>a[:]</code> returns a copy of the entire list. Each element of a slice is a [[shallow copy]].<br />
<br />
In Python, a distinction between expressions and statements is rigidly enforced, in contrast to languages such as [[Common Lisp]], [[Scheme (programming language)|Scheme]], or [[Ruby (programming language)|Ruby]]. This leads to duplicating some functionality. For example:<br />
<br />
* [[List comprehensions]] vs. <code>for</code>-loops<br />
* [[Conditional (programming)|Conditional]] expressions vs. <code>if</code> blocks<br />
* The <code>eval()</code> vs. <code>exec()</code> built-in functions (in Python 2, <code>exec</code> is a statement); the former is for expressions, the latter is for statements.<br />
<br />
Statements cannot be a part of an expression, so list and other comprehensions or [[Lambda (programming)|lambda expressions]], all being expressions, cannot contain statements. A particular case of this is that an assignment statement such as <code>a = 1</code> cannot form part of the conditional expression of a conditional statement. This has the advantage of avoiding a classic C error of mistaking an assignment operator <code>=</code> for an equality operator <code>==</code> in conditions: <code>if (c = 1) { ... }</code> is syntactically valid (but probably unintended) C code but <code>if c = 1: ...</code> causes a syntax error in Python.<br />
<br />
=== Methods ===<br />
[[Method (programming)|Methods]] on objects are [[function (programming)|functions]] attached to the object's class; the syntax <code>instance.method(argument)</code> is, for normal methods and functions, [[syntactic sugar]] for <code>Class.method(instance, argument)</code>. Python methods have an explicit <code>[[this (computer programming)|self]]</code> parameter to access [[instance data]], in contrast to the implicit <code>self</code> (or <code>this</code>) in some other object-oriented programming languages (e.g., [[C++]], [[Java (programming language)|Java]], [[Objective-C]], or [[Ruby (programming language)|Ruby]]).<ref name="AutoNT-61" /><br />
<br />
=== Typing ===<br />
[[File:Python 3. The standard type hierarchy.png|thumb|The standard type hierarchy in Python 3]]<br />
Python uses [[duck typing]] and has typed objects but untyped variable names. Type constraints are not checked at [[compile time]]; rather, operations on an object may fail, signifying that the given object is not of a suitable type. Despite being [[Type system#Dynamic type checking and runtime type information|dynamically typed]], Python is [[strongly typed programming language|strongly typed]], forbidding operations that are not well-defined (for example, adding a number to a string) rather than silently attempting to make sense of them.<br />
<br />
Python allows programmers to define their own types using [[class (computer science)|classes]], which are most often used for [[object-oriented programming]]. New [[object (computer science)|instances]] of classes are constructed by calling the class (for example, <code>SpamClass()</code> or <code>EggsClass()</code>), and the classes are instances of the [[metaclass]] <code>type</code> (itself an instance of itself), allowing [[metaprogramming]] and [[reflection (computer science)|reflection]].<br />
<br />
Before version 3.0, Python had two kinds of classes: ''old-style'' and ''new-style''.<ref name="classy" /> The syntax of both styles is the same, the difference being whether the class <code>object</code> is inherited from, directly or indirectly (all new-style classes inherit from <code>object</code> and are instances of <code>type</code>). In versions of Python 2 from Python 2.2 onwards, both kinds of classes can be used. Old-style classes were eliminated in Python 3.0.<br />
<br />
The long term plan is to support [[gradual typing]]<ref>{{cite web |url=https://lwn.net/Articles/627418/ |title=Type hinting for Python |publisher=LWN.net |date=24 December 2014 |accessdate=5 May 2015}}</ref> and from Python 3.5, the syntax of the language allows specifying static types but they are not checked in the default implementation, CPython. An experimental optional static type checker named ''mypy'' supports compile-time type checking.<ref>{{cite web |url=http://mypy-lang.org/ |title=mypy - Optional Static Typing for Python |accessdate=28 January 2017}}</ref><br />
<br />
{|class="wikitable"<br />
|+Summary of Python 3's built-in types<br />
|-<br />
! Type<br />
! [[immutable object|Mutability]]<br />
! Description<br />
! style="width: 23em;" | Syntax examples<br />
|-<br />
| <code>bool</code><br />
| immutable<br />
| [[Boolean value]]<br />
| {{code|lang=python|True}}<br>{{code|lang=python|False}}<br />
|-<br />
| <code>bytearray</code><br />
| mutable<br />
| Sequence of [[byte]]s<br />
| {{code|lang=python|bytearray(b'Some ASCII')}}<br>{{code|lang=python|bytearray(b"Some ASCII")}}<br>{{code|lang=python|bytearray([119, 105, 107, 105])}}<br />
|-<br />
| <code>bytes</code><br />
| immutable<br />
| Sequence of bytes<br />
| {{code|lang=python|b'Some ASCII'}}<br>{{code|lang=python|b"Some ASCII"}}<br>{{code|lang=python|bytes([119, 105, 107, 105])}}<br />
|-<br />
| <code>complex</code><br />
| immutable<br />
| [[Complex number]] with real and imaginary parts<br />
| {{code|lang=python|3+2.7j}}<br />
|-<br />
| <code>dict</code><br />
| mutable<br />
| [[Associative array]] (or dictionary) of key and value pairs; can contain mixed types (keys and values), keys must be a hashable type<br />
| {{code|lang=python|{'key1': 1.0, 3: False} }}<br>{{code|lang=python|{} }}<br />
|-<br />
| <code>ellipsis</code>{{ref|inaccessible-type|a}}<br />
| immutable<br />
| An [[Ellipsis (programming operator)|ellipsis]] placeholder to be used as an index in [[NumPy]] arrays<br />
| {{code|lang=python|...}}<br>{{code|lang=python|Ellipsis}}<br />
|-<br />
| <code>float</code><br />
| immutable<br />
| [[Double precision]] [[floating point]] number. The precision is machine dependent but in practice is 64 bits.{{Citation needed|date=December 2019}}<br />
| {{code|lang=python|3.1415927}}<br />
|-<br />
| <code>frozenset</code><br />
| immutable<br />
| Unordered [[Set (computer science)|set]], contains no duplicates; can contain mixed types, if hashable<br />
| {{code|lang=python|frozenset([4.0, 'string', True])}}<br />
|-<br />
| <code>int</code><br />
| immutable<br />
| [[Integer (computer science)|Integer]] of unlimited magnitude<ref name="pep0237" /><br />
| {{code|lang=python|42}}<br />
|-<br />
| <code>list</code><br />
| mutable<br />
| [[list (computer science)|List]], can contain mixed types<br />
| {{code|lang=python|[4.0, 'string', True]}}<br>{{code|lang=python|[]}}<br />
|-<br />
| <code>NoneType</code>{{ref|inaccessible-type|a}}<br />
| immutable<br />
| An object representing the absence of a value, often called [[Null pointer|Null]] in other languages<br />
| {{code|lang=python|None}}<br />
|-<br />
| <code>NotImplementedType</code>{{ref|inaccessible-type|a}}<br />
| immutable<br />
| A placeholder that can be returned from [[Operator overloading|overloaded operators]] to indicate unsupported operand types.<br />
| {{code|lang=python|NotImplemented}}<br />
|-<br />
| <code>range</code><br />
| immutable<br />
| A Sequence of numbers commonly used for looping specific number of times in <code>for</code> loops<ref>{{cite web |title=Built-in Types |url=https://docs.python.org/3/library/stdtypes.html#typesseq-range |accessdate=3 October 2019}}</ref><br />
| {{code|lang=python|range(1, 10)}}<br>{{code|lang=python|range(10, -5, -2)}} <br />
|-<br />
| <code>set</code><br />
| mutable<br />
| Unordered [[set (computer science)|set]], contains no duplicates; can contain mixed types, if hashable<br />
| {{code|lang=python|{4.0, 'string', True} }}<br>{{code|lang=python|set()}}<br />
|-<br />
| <code>str</code><br />
| immutable<br />
| A [[string (computer science)|character string]]: sequence of Unicode codepoints<br />
| {{code|lang=python|'Wikipedia'}}<br>{{code|lang=python|"Wikipedia"}}<br><syntaxhighlight lang="python">"""Spanning<br />
multiple<br />
lines"""</syntaxhighlight><br />
|-<br />
| <code>tuple</code><br />
| immutable<br />
| Can contain mixed types<br />
| {{code|lang=python|(4.0, 'string', True)}}<br>{{code|lang=python|('single element',)}}<br>{{code|lang=python|()}}<br />
|}<br />
<br />
{{note|inaccessible-type|a|Not directly accessible by name}}<br />
<br />
=== Mathematics ===<br />
Python has the usual symbols for arithmetic operators (<code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>), and the [[modulo operation|remainder operator]] <code>%</code> (where the remainder can be negative, <!--unlike in C language depending on compiler,<ref>{{Cite web|url=https://stackoverflow.com/questions/11720656/modulo-operation-with-negative-numbers/42131603|title=c - Modulo operation with negative numbers|quote=Note that, in C89, whether the result round upward or downward is implementation-defined.|website=Stack Overflow|access-date=2019-09-25}}</ref>--> e.g. <code>4 % -3 == -2</code>). It also has <code>**</code> for exponentiation, e.g. <code>5**3 == 125</code> and <code>9**0.5 == 3.0</code>, and a matrix multiply <code>@</code> operator.<ref>{{cite web |url=https://legacy.python.org/dev/peps/pep-0465/ |title=PEP 465 -- A dedicated infix operator for matrix multiplication |work=python.org}}</ref> These operators work like in traditional math; with the same [[order of operations|precedence rules]], the operators [[Infix notation|infix]] ( <code>+</code> and <code>-</code> can also be unary to represent positive and negative numbers respectively). Additionally, it has a unary operator (<code>~</code>), which essentially inverts all the bits of its one argument. For integers, this means <code>~x=-x-1</code>.<ref>{{cite web |url=https://stackoverflow.com/questions/8305199/the-tilde-operator-in-python |title=The tilde operator in Python - Stackoverflow |work=stackoverflow.com}}</ref> Other operators include bitwise shift operators <code>x << y</code>, which shifts <code>x</code> to the left <code>y</code> places, the same as <code>x*(2**y) </code>, and <code>x >> y</code>, which shifts <code>x</code> to the right <code>y</code> places, the same as <code>x//(2**y)</code>.<ref>{{cite web |url=https://wiki.python.org/moin/BitwiseOperators |title=BitwiseOperators - Python Wiki |work=wiki.python.org}}</ref><br />
<br />
The behavior of division has changed significantly over time so that division between integers produces floating point results:<ref name="pep0238"/><br />
<br />
* Python 2.1 and earlier used C's division behavior. The <code>/</code> operator is integer division if both operands are integers, and floating-point division otherwise. Integer division rounds towards 0, e.g. {{nowrap|1=<code>7/3 == 2</code>}} and {{nowrap|1=<code>-7/3 == -2</code>.}}<br />
* Python 2.2 changed integer division to round towards negative infinity, e.g. <code>7/3 == 2</code> and <code>-7/3 == -3</code>. The floor division <code>//</code> operator was introduced. So <code>7//3 == 2</code>, <code>-7//3 == -3</code>, <code>7.5//3 == 2.0</code> and <code>-7.5//3 == -3.0</code>. Adding <code>from __future__ import division</code> causes a module to use Python 3.0 rules for division (see next).<br />
* Python 3.0 changed <code>/</code> to always be floating-point division, e.g. {{nowrap|1=<code>5/2 == 2.5</code>}}.<br />
<br />
In Python terms, <code>/</code> before version 3.0 is ''classic division'', <code>/</code> in versions 3.0 and higher is ''true division'', and <code>//</code> is ''floor division''.<ref name="pep0238"/><br />
<br />
Rounding towards negative infinity, though different from most languages, adds consistency. For instance, it means that the equation <code>(a + b)//b == a//b + 1</code> is always true. It also means that the equation <code>b*(a//b) + a%b == a</code> is valid for both positive and negative values of <code>a</code>. However, maintaining the validity of this equation means that while the result of <code>a%b</code> is, as expected, in the [[half-open interval]] [0, ''b''), where <code>b</code> is a positive integer, it has to lie in the interval (''b'', 0] when <code>b</code> is negative.<ref name="AutoNT-62" /><br />
<br />
Python provides a <code>round</code> function for [[rounding]] a float to the nearest integer. For [[Rounding#Tie-breaking|tie-breaking]], versions before 3 use round-away-from-zero: <code>round(0.5)</code> is 1.0, <code>round(-0.5)</code> is −1.0.<ref name="AutoNT-63" /> Python 3 uses [[round to even]]: <code>round(1.5)</code> is 2, <code>round(2.5)</code> is 2.<ref name="AutoNT-64" /><br />
<br />
Python allows boolean expressions with multiple equality relations in a manner that is consistent with general use in mathematics. For example, the expression <code>a < b < c</code> tests whether <code>a</code> is less than <code>b</code> and <code>b</code> is less than <code>c</code>.<ref name="AutoNT-65" /> C-derived languages interpret this expression differently: in C, the expression would first evaluate <code>a < b</code>, resulting in 0 or 1, and that result would then be compared with <code>c</code>.<ref name="CPL" /><br />
<br />
Python has extensive built-in support for [[arbitrary-precision arithmetic]]. Integers are transparently switched from the machine-supported maximum fixed-precision (usually 32 or 64 bits), belonging to the python type <code>int</code>, to arbitrary precision, belonging to the Python type <code>long</code>, where needed. The latter have an "L" suffix in their textual representation.<ref>{{cite web|title = Built-in Type|url = https://docs.python.org/2.7/library/stdtypes.html|website = docs.python.org}}</ref> (In Python 3, the distinction between the <code>int</code> and <code>long</code> types was eliminated; this behavior is now entirely contained by the <code>int</code> class.) The <code>Decimal</code> type/class in module <code>decimal</code> (since version 2.4) provides decimal floating point numbers to arbitrary precision and several rounding modes.<ref>{{cite web|title = PEP 0327 -- Decimal Data Type|url = https://www.python.org/dev/peps/pep-0327/|website = Python.org|accessdate = 26 September 2015|last = Batista|first = Facundo}}</ref> The <code>Fraction</code> type in module <code>fractions</code> (since version 2.6) provides arbitrary precision for rational numbers.<ref>{{cite web|title = What's New in Python 2.6 — Python v2.6.9 documentation|url = https://docs.python.org/2.6/whatsnew/2.6.html|website = docs.python.org|accessdate = 26 September 2015}}</ref><br />
<br />
Due to Python's extensive mathematics library, and the third-party library [[NumPy]] that further extends the native capabilities, it is frequently used as a scientific scripting language to aid in problems such as numerical data processing and manipulation.<ref>{{Cite web|url=https://www.stat.washington.edu/~hoytak/blog/whypython.html|title=10 Reasons Python Rocks for Research (And a Few Reasons it Doesn't) — Hoyt Koepke|website=www.stat.washington.edu|access-date=2019-02-03}}</ref><ref>{{Cite web|url=https://engineering.ucsb.edu/~shell/che210d/python.pdf|title=An introduction to Python for scientific computing|last=Shell|first=Scott|date=17 June 2014|website=|access-date=3 Feb 2019}}</ref><br />
<br />
== Python programming examples ==<br />
[["Hello, World!" program|Hello world]] program:<br />
<syntaxhighlight lang="python"><br />
print('Hello, world!')<br />
</syntaxhighlight><br />
<br />
Program to calculate the [[factorial]] of a positive integer:<br />
<syntaxhighlight lang="python"><br />
n = int(input('Type a number, then its factorial will be printed: '))<br />
<br />
if n < 0:<br />
raise ValueError('You must enter a positive number')<br />
<br />
fact = 1<br />
i = 2<br />
while i <= n:<br />
fact = fact * i<br />
i += 1<br />
<br />
print(fact)<br />
</syntaxhighlight><br />
<br />
== Libraries ==<br />
Python's large [[standard library]], commonly cited as one of its greatest strengths,<ref name="AutoNT-86" /> provides tools suited to many tasks. For Internet-facing applications, many standard formats and protocols such as [[MIME]] and [[Hypertext Transfer Protocol|HTTP]] are supported. It includes modules for creating [[graphical user interface]]s, connecting to [[relational database]]s, [[pseudorandom number generator|generating pseudorandom numbers]], arithmetic with arbitrary-precision decimals,<ref name="AutoNT-88" /> manipulating [[regular expression]]s, and [[unit testing]].<br />
<br />
Some parts of the standard library are covered by specifications (for example, the [[Web Server Gateway Interface]] (WSGI) implementation <code>wsgiref</code> follows PEP 333<ref name="AutoNT-89" />), but most modules are not. They are specified by their code, internal documentation, and test suites (if supplied). However, because most of the standard library is cross-platform Python code, only a few modules need altering or rewriting for variant implementations.<br />
<br />
{{As of|2019|11|post=,}} the [[Python Package Index]] (PyPI), the official repository for third-party Python software, contains over 200,000<ref>{{cite web |url=http://www.modulecounts.com/ |title=Module Counts |date=|website=ModuleCounts |last1=Debill|first1=Erik |accessdate=5 November 2019}}</ref> packages with a wide range of functionality, including:<br />
<br />
* [[Graphical user interfaces]]<br />
* [[Web framework]]s<br />
* [[Multimedia]]<br />
* [[Databases]]<br />
* Networking <br />
* [[Test framework]]s<br />
* [[Automation]]<br />
* [[Web scraping]]<ref>{{cite web|url=https://likegeeks.com/python-web-scraping/|title=20+ Python Web Scraping Examples (Beautiful Soup & Selenium) - Like Geeks|date=5 December 2017|website=likegeeks.com|accessdate=12 March 2018}}</ref><br />
* Documentation<br />
* [[System administration]]<br />
* [[Scientific computing]]<br />
* [[Text processing]]<br />
* [[Image processing]]<br />
* [[Machine learning]]<br />
* [[Data analytics]]<br />
<br />
== Development environments ==<br />
{{See also|Comparison of integrated development environments#Python}}<br />
<br />
Most Python implementations (including CPython) include a [[read–eval–print loop]] (REPL), permitting them to function as a [[command line interpreter]] for which the user enters statements sequentially and receives results immediately.<br />
<br />
Other shells, including [[IDLE (Python)|IDLE]] and [[IPython]], add further abilities such as auto-completion, session state retention and [[syntax highlighting]].<br />
<br />
As well as standard desktop [[integrated development environment]]s, there are [[Web browser]]-based IDEs; [[SageMath]] (intended for developing science and math-related Python programs); [[PythonAnywhere]], a browser-based IDE and hosting environment; and Canopy IDE, a commercial Python IDE emphasizing [[scientific computing]].<ref>{{cite web|last1=Enthought|first1=Canopy |title=Canopy |url=https://www.enthought.com/products/canopy/|website=www.enthought.com |accessdate=20 August 2016}}</ref><br />
<br />
== Implementations ==<br />
{{See also|List of Python software#Python implementations}}<br />
<br />
=== Reference implementation ===<br />
[[CPython]] is the [[reference implementation]] of Python. It is written in [[C (programming language)|C]], meeting the [[C89 (C version)|C89]] standard with several select [[C99]] features.<ref name="AutoNT-66" /> It compiles Python programs into an intermediate [[bytecode]]<ref name="AutoNT-67" /> which is then executed by its [[virtual machine]].<ref name="AutoNT-68" /> CPython is distributed with a large standard library written in a mixture of C and native Python. It is available for many platforms, including [[Microsoft Windows|Windows]] and most modern [[Unix-like]] systems. Platform portability was one of its earliest priorities.<ref name="AutoNT-69" /><br />
<br />
=== Other implementations ===<br />
[[PyPy]] is a fast, compliant interpreter of Python 2.7 and 3.5.<ref name="AutoNT-70" /> Its [[Just-in-time compilation|just-in-time compiler]] brings a significant speed improvement over CPython but several libraries written in C cannot be used with it.<ref name="AutoNT-71" /><ref>{{cite web|url=https://hackernoon.com/which-is-the-fastest-version-of-python-2ae7c61a6b2b|title=Which is the fastest version of Python?|first=Anthony|last=Shaw|publisher=Hacker Noon|date=2018-03-30|accessdate=2019-12-20}}</ref><br />
<br />
[[Stackless Python]] is a significant fork of CPython that implements [[microthread]]s; it does not use the C memory stack, thus allowing massively concurrent programs. PyPy also has a stackless version.<ref name="AutoNT-73" /><br />
<br />
[[MicroPython]] and [[CircuitPython]] are Python 3 variants optimized for [[microcontroller]]s. This includes [[Lego Mindstorms EV3]].<ref>{{Cite web|url=https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3|title=Python-for-EV3|website=LEGO Education|language=en|access-date=2019-04-17}}</ref><br />
<br />
RustPython is a Python 3 interpreter written in [[Rust (programming language)|Rust]].<ref>{{Citation|title=GitHub - RustPython/RustPython: A Python Interpreter written in Rust.|date=2019-09-13|url=https://github.com/RustPython/RustPython|publisher=RustPython|access-date=2019-09-13}}</ref><br />
<br />
=== Unsupported implementations ===<br />
Other just-in-time Python compilers have been developed, but are now unsupported:<br />
<br />
* Google began a project named [[Unladen Swallow]] in 2009, with the aim of speeding up the Python interpreter five-fold by using the [[LLVM]], and of improving its multithreading ability to scale to thousands of cores,<ref name="AutoNT-74" /> while ordinary implementations suffer from the [[global interpreter lock]].<br />
* [[Psyco]] is a [[Just-in-time compilation|just-in-time]] [[Run-time algorithm specialisation|specialising]] compiler that integrates with CPython and transforms bytecode to machine code at runtime. The emitted code is specialized for certain [[data type]]s and is faster than standard Python code.<br />
<br />
In 2005, [[Nokia]] released a Python interpreter for the [[Series 60]] mobile phones named [[PyS60]]. It includes many of the modules from the CPython implementations and some additional modules to integrate with the [[Symbian]] operating system. The project has been kept up-to-date to run on all variants of the S60 platform, and several third-party modules are available. The Nokia [[N900]] also supports Python with [[GTK]] widget libraries, enabling programs to be written and run on the target device.<ref>{{cite web |title=Python on the Nokia N900 |url=http://www.stochasticgeometry.ie/2010/04/29/python-on-the-nokia-n900/|website=Stochastic Geometry|date=2010-04-29}}</ref><br />
<br />
=== Cross-compilers to other languages ===<br />
There are several compilers to high-level [[object language]]s, with either unrestricted Python, a restricted subset of Python, or a language similar to Python as the source language:<br />
<br />
* [[Jython]] enables the use of the Java class library from a Python program.<br />
* [[IronPython]] follows a similar approach in order to run Python programs on the .NET [[Common Language Runtime]].<br />
* The [[RPython]] language can be compiled to [[C (programming language)|C]], and is used to build the PyPy interpreter of Python.<br />
* [[Pyjs]] compiles Python to [[JavaScript]].<br />
* [[Cython]] compiles Python to [[C (programming language)|C]] and [[C++]].<br />
* [[Numba]] uses [[LLVM]] to compile Python to machine code.<br />
* Pythran compiles Python to [[C++]].<br />
* Somewhat dated [[Pyrex (programming language)|Pyrex]] (latest release in 2010) and [[Shed Skin]] (latest release in 2013) compile to C and C++ respectively.<br />
* Google's Grumpy compiles Python to [[Go (programming language)|Go]].<br />
* [[MyHDL]] compiles Python to [[VHDL]].<br />
* [[Nuitka]] compiles Python into C++.<ref>{{cite web|url=http://nuitka.net/|title=Nuitka Home {{!}} Nuitka Home|website=nuitka.net|language=en|access-date=18 August 2017}}</ref><br />
<br />
=== Performance ===<br />
A performance comparison of various Python implementations on a non-numerical (combinatorial) workload was presented at EuroSciPy '13.<ref>{{cite conference |title=Performance of Python runtimes on a non-numeric scientific code |last=Murri |first=Riccardo |conference=European Conference on Python in Science (EuroSciPy) |year=2013 |arxiv=1404.6388|bibcode=2014arXiv1404.6388M }}</ref><br />
<br />
== Development ==<br />
Python's development is conducted largely through the ''Python Enhancement Proposal'' (PEP) process, the primary mechanism for proposing major new features, collecting community input on issues and documenting Python design decisions.<ref name="PepCite000" /> Python coding style is covered in PEP 8.<ref>{{cite web|url=https://www.python.org/dev/peps/pep-0008/|title=PEP 8 -- Style Guide for Python Code|website=Python.org}}</ref> Outstanding PEPs are reviewed and commented on by the Python community and the steering council.<ref name="PepCite000" /><br />
<br />
Enhancement of the language corresponds with development of the CPython reference implementation. The mailing list python-dev is the primary forum for the language's development. Specific issues are discussed in the [[Roundup (issue tracker)|Roundup]] [[bug tracker]] maintained at python.org.<ref name="AutoNT-21" /> Development originally took place on a [[Self-hosting (web services)|self-hosted]] source-code repository running [[Mercurial]], until Python moved to [[GitHub]] in January 2017.<ref name=py_dev_guide>{{cite web |title=Python Developer's Guide |url=https://docs.python.org/devguide/}}</ref><br />
<br />
CPython's public releases come in three types, distinguished by which part of the version number is incremented:<br />
<br />
* Backward-incompatible versions, where code is expected to break and need to be manually [[ported]]. The first part of the version number is incremented. These releases happen infrequently—for example, version 3.0 was released 8 years after 2.0.<br />
* Major or "feature" releases, about every 18 months, are largely compatible but introduce new features. The second part of the version number is incremented. Each major version is supported by bugfixes for several years after its release.<ref name="release-schedule" /><br />
* Bugfix releases, which introduce no new features, occur about every 3 months and are made when a sufficient number of bugs have been fixed upstream since the last release. Security vulnerabilities are also patched in these releases. The third and final part of the version number is incremented.<ref name="AutoNT-22" /><br />
<br />
Python 3.9 alpha1 was announced in November 2019,<ref>{{Cite web|url=https://docs.python.org/3.9/whatsnew/3.9.html|title=What’s New In Python 3.9|last=|first=|date=|website=Python|url-status=live|archive-url=|archive-date=|access-date=2019-11-28}}</ref> but the release date for the final version depends on what new proposal for release dates are adopted with three draft proposals under discussion, and a yearly cadence is one option.<ref>{{Cite web|url=https://www.python.org/dev/peps/pep-0605/|title=PEP 605 -- A rolling feature release stream for CPython|website=Python.org|language=en|access-date=2019-11-06}}</ref><ref>{{Cite web|url=https://www.python.org/dev/peps/pep-0602/|title=PEP 602 -- Annual Release Cycle for Python|website=Python.org|language=en|access-date=2019-11-06}}</ref><ref>{{Cite web|url=https://www.python.org/dev/peps/pep-0596/|title=PEP 596 -- Python 3.9 Release Schedule|website=Python.org|language=en|access-date=2019-11-06}}</ref><ref>{{Cite web|url=https://lwn.net/Articles/802777/|title=Changing the Python release cadence [LWN.net]|website=lwn.net|access-date=2019-11-06}}</ref><br />
<br />
Many [[beta release|alpha, beta, and release-candidates]] are also released as previews and for testing before final releases. Although there is a rough schedule for each release, they are often delayed if the code is not ready. Python's development team monitors the state of the code by running the large [[unit test]] suite during development, and using the [[BuildBot]] [[continuous integration]] system.<ref name="AutoNT-23" /><br />
<br />
The community of Python developers has also contributed over 206,000<ref>{{cite web|last1=DeBill|first1=Erik |title=Module Counts |url=http://www.modulecounts.com/#|website=www.modulecounts.com |accessdate=29 November 2019}}</ref> software modules ({{as of|2019|11|29|lc=yes}}) to the [[Python Package Index]] (PyPI), the official repository of third-party Python libraries.<br />
<br />
The major [[academic conference]] on Python is [[PyCon]]. There are also special Python mentoring programmes, such as [[Pyladies]].<br />
<br />
== Naming ==<br />
Python's name is derived from the British comedy group [[Monty Python]], whom Python creator Guido van Rossum enjoyed while developing the language. Monty Python references appear frequently in Python code and culture;<ref name="tutorial-chapter1" /> for example, the [[metasyntactic variable]]s often used in Python literature are [[Spam (Monty Python)|''spam'' and ''eggs'']] instead of the traditional [[foobar|''foo'' and ''bar'']].<ref name="tutorial-chapter1" /><ref name="AutoNT-26" /> The official Python documentation also contains various references to Monty Python routines.<ref>{{cite book |last1=Lutz |first1=Mark |title=Learning Python: Powerful Object-Oriented Programming |year=2009 |publisher=O'Reilly Media, Inc. |isbn=9781449379322 |page=17 |url=https://books.google.com/books?id=1HxWGezDZcgC&pg=PA17 |language=en}}</ref><ref>{{cite book |last1=Fehily |first1=Chris |title=Python |year=2002 |publisher=Peachpit Press |isbn=9780201748840 |page=xv |url=https://books.google.com/books?id=carqdIdfVlYC&pg=PR15 |language=en}}</ref><br />
<br />
The prefix ''Py-'' is used to show that something is related to Python. Examples of the use of this prefix in names of Python applications or libraries include [[Pygame]], a [[language binding|binding]] of [[Simple DirectMedia Layer|SDL]] to Python (commonly used to create games); [[PyQt]] and [[PyGTK]], which bind [[Qt (software)|Qt]] and [[GTK]] to Python respectively; and [[PyPy]], a Python implementation originally written in Python.<br />
<br />
== API documentation generators ==<br />
Python API documentation generators include:<br />
<br />
* [[Sphinx (documentation generator)|Sphinx]]<br />
* [[Epydoc]]<br />
* [[HeaderDoc]]<br />
* [[pydoc]]<br />
<br />
== Uses ==<br />
{{Main|List of Python software}}<br />
Since 2003, Python has consistently ranked in the top ten most popular programming languages in the [[TIOBE Programming Community Index]] where, {{as of|2020|2|lc=y|df=}}, it is the third most popular language (behind [[Java (programming language)|Java]], and [[C (programming language)|C]]).<ref>{{cite web |url=http://www.tiobe.com/tiobe-index/ |title=TIOBE Index |publisher=TIOBE - The Software Quality Company |accessdate=7 March 2017}}</ref> It was selected Programming Language of the Year in 2007, 2010, and 2018.<ref name="AutoNT-34" /><br />
<br />
An empirical study found that scripting languages, such as Python, are more productive than conventional languages, such as C and Java, for programming problems involving string manipulation and search in a dictionary, and determined that memory consumption was often "better than Java and not much worse than C or C++".<ref name="AutoNT-28" /><br />
<br />
Large organizations that use Python include [[Wikipedia]], [[Google]],<ref name="quotes-about-python" /> [[Yahoo!]],<ref name="AutoNT-29" /> [[CERN]],<ref name="AutoNT-30" /> [[NASA]],<ref name="AutoNT-31" /> [[Facebook]],<ref>{{Cite web|url=https://developers.facebook.com/blog/post/301|title=Tornado: Facebook's Real-Time Web Framework for Python - Facebook for Developers|website=Facebook for Developers|language=en-US|access-date=2018-06-19}}</ref> [[Amazon (company)|Amazon]], [[Instagram]],<ref>{{cite web |url=https://instagram-engineering.com/what-powers-instagram-hundreds-of-instances-dozens-of-technologies-adf2e22da2ad |title=What Powers Instagram: Hundreds of Instances, Dozens of Technologies |publisher=Instagram Engineering |accessdate=27 May 2019}}</ref> [[Spotify]]<ref>{{Cite web|url=https://labs.spotify.com/2013/03/20/how-we-use-python-at-spotify/|title=How we use Python at Spotify|website=Spotify Labs|language=en-US|access-date=2018-07-25|date=2013-03-20}}</ref> and some smaller entities like [[Industrial Light & Magic|ILM]]<ref name="AutoNT-32" /> and [[ITA Software|ITA]].<ref name="AutoNT-33" /> The social news networking site [[Reddit]] is written entirely in Python.<ref>{{Citation|title=GitHub - reddit-archive/reddit: historical code from reddit.com.|date=2019-03-19|url=https://github.com/reddit-archive/reddit|publisher=The Reddit Archives|access-date=2019-03-20}}</ref><br />
<br />
Python can serve as a [[scripting language]] for [[web application]]s, e.g., via [[mod_wsgi]] for the [[Apache web server]].<ref name="AutoNT-35" /> With [[Web Server Gateway Interface]], a standard API has evolved to facilitate these applications. [[Web framework]]s like [[Django (web framework)|Django]], [[Pylons (web framework)|Pylons]], [[Pyramid (web framework)|Pyramid]], [[TurboGears]], [[web2py]], [[Tornado (web server)|Tornado]], [[Flask (web framework)|Flask]], [[Bottle (web framework)|Bottle]] and [[Zope]] support developers in the design and maintenance of complex applications. [[Pyjs]] and [[IronPython]] can be used to develop the client-side of Ajax-based applications. [[SQLAlchemy]] can be used as [[Data mapper pattern|data mapper]] to a relational database. [[Twisted (software)|Twisted]] is a framework to program communications between computers, and is used (for example) by [[Dropbox (service)|Dropbox]].<br />
<br />
Libraries such as [[NumPy]], [[SciPy]] and [[Matplotlib]] allow the effective use of Python in [[scientific computing]],<ref name="cise">{{cite journal |last=Oliphant |first=Travis |title=Python for Scientific Computing |journal=Computing in Science and Engineering |volume=9 |issue=3 |pages=10–20 |year=2007 |url=https://www.h2desk.com/blog/python-scientific-computing/|doi=10.1109/MCSE.2007.58 |citeseerx=10.1.1.474.6460 |bibcode=2007CSE.....9c..10O }}</ref><ref name="millman">{{cite journal |first1=K. Jarrod |last1=Millman |first2=Michael |last2=Aivazis |title=Python for Scientists and Engineers |journal=Computing in Science and Engineering |volume=13 |number=2 |pages=9–12 |year=2011 |url=http://www.computer.org/csdl/mags/cs/2011/02/mcs2011020009.html|doi=10.1109/MCSE.2011.36 |bibcode=2011CSE....13b...9M }}</ref> with specialized libraries such as [[Biopython]] and [[Astropy]] providing domain-specific functionality. [[SageMath]] is a [[mathematical software]] with a [[notebook interface]] programmable in Python: its library covers many aspects of [[mathematics]], including [[algebra]], [[combinatorics]], [[numerical mathematics]], [[number theory]], and [[calculus]].<br />
<br />
Python has been successfully embedded in many software products as a scripting language, including in [[finite element method]] software such as [[Abaqus]], 3D parametric modeler like [[FreeCAD]], 3D animation packages such as [[3ds Max]], [[Blender (software)|Blender]], [[Cinema 4D]], [[Lightwave]], [[Houdini (software)|Houdini]], [[Maya (software)|Maya]], [[modo (software)|modo]], [[MotionBuilder]], [[Autodesk Softimage|Softimage]], the visual effects compositor [[Nuke (software)|Nuke]], 2D imaging programs like [[GIMP]],<ref>{{cite web |url=http://gimp-win.sourceforge.net/faq.html |title=Installers for GIMP for Windows - Frequently Asked Questions |author=<!-- Staff writer(s); no by-line. --> |date=26 July 2013 |accessdate=26 July 2013 |url-status=dead |archiveurl=https://web.archive.org/web/20130717070814/http://gimp-win.sourceforge.net/faq.html |archivedate=17 July 2013 |df=dmy-all }}</ref> [[Inkscape]], [[Scribus]] and [[Paint Shop Pro]],<ref name="AutoNT-38" /> and [[musical notation]] programs like [[scorewriter]] and [[Capella (notation program)|capella]]. [[GNU Debugger]] uses Python as a [[Prettyprint|pretty printer]] to show complex structures such as C++ containers. [[Esri]] promotes Python as the best choice for writing scripts in [[ArcGIS]].<ref name="AutoNT-39" /> It has also been used in several video games,<ref name="AutoNT-40" /><ref name="AutoNT-41" /> and has been adopted as first of the three available [[programming language]]s in [[Google App Engine]], the other two being [[Java (software platform)|Java]] and [[Go (programming language)|Go]].<ref name="AutoNT-42" /><br />
<br />
Python is commonly used in [[artificial intelligence]] projects with the help of libraries like [[TensorFlow]], [[Keras]] and [[Scikit-learn]].<ref name=whitepaper2015>{{cite web |last1 = Dean |first1 = Jeff |last2 = Monga |first2 = Rajat |first3 = Sanjay |last3 = Ghemawat |display-authors = 2 |authorlink1 = Jeff Dean (computer scientist) |title = TensorFlow: Large-scale machine learning on heterogeneous systems |url = http://download.tensorflow.org/paper/whitepaper2015.pdf |website = TensorFlow.org |publisher = Google Research |accessdate = 10 November 2015 |date = 9 November 2015 }}</ref><ref>{{cite web |last1=Piatetsky |first1=Gregory |title=Python eats away at R: Top Software for Analytics, Data Science, Machine Learning in 2018: Trends and Analysis |url=https://www.kdnuggets.com/2018/05/poll-tools-analytics-data-science-machine-learning-results.html/2 |website=KDnuggets |publisher=KDnuggets |accessdate=30 May 2018}}</ref><ref>{{cite web|url=https://scikit-learn.org/stable/testimonials/testimonials.html|title=Who is using scikit-learn? — scikit-learn 0.20.1 documentation|website=scikit-learn.org}}</ref><ref>{{cite web |authorlink1=Norman Jouppi|last1 = Jouppi |first1 = Norm |title = Google supercharges machine learning tasks with TPU custom chip |url = https://cloudplatform.googleblog.com/2016/05/Google-supercharges-machine-learning-tasks-with-custom-chip.html |website = Google Cloud Platform Blog |accessdate = 19 May 2016 }}</ref> As a scripting language with [[modular programming|modular architecture]], simple syntax and rich text processing tools, Python is often used for [[natural language processing]].<ref name="AutoNT-47" /><br />
<br />
Many operating systems include Python as a standard component. It ships with most [[Linux distribution]]s<ref>{{Cite web|url=https://docs.python.org/3/using/unix.html|title=Python Setup and Usage|last=|first=|date=|website=|publisher=Python Software Foundation|url-status=live|archive-url=|archive-date=|access-date=10 January 2020}}</ref>, [[AmigaOS 4]], [[FreeBSD]] (as a package), [[NetBSD]], [[OpenBSD]] (as a package) and [[macOS]] and can be used from the command line (terminal). Many Linux distributions use installers written in Python: [[Ubuntu (operating system)|Ubuntu]] uses the [[Ubiquity (software)|Ubiquity]] installer, while [[Red Hat Linux]] and [[Fedora (operating system)|Fedora]] use the [[Anaconda (installer)|Anaconda]] installer. [[Gentoo Linux]] uses Python in its [[package management system]], [[Portage (software)|Portage]].<br />
<br />
Python is used extensively in the [[information security]] industry, including in exploit development.<ref name="AutoNT-49" /><ref name="AutoNT-50" /><br />
<br />
Most of the [[Sugar (software)|Sugar]] software for the [[One Laptop per Child]] XO, now developed at [[Sugar Labs]], is written in Python.<ref name="AutoNT-51" /> The [[Raspberry Pi]] [[single-board computer]] project has adopted Python as its main user-programming language.<br />
<br />
[[LibreOffice]] includes Python, and intends to replace Java with Python. Its Python Scripting Provider is a core feature<ref>{{cite web |title=4.0 New Features and Fixes |publisher=[[The Document Foundation]] |work=LibreOffice.org |year=2013 |url=http://www.libreoffice.org/download/4-0-new-features-and-fixes/ |accessdate=25 February 2013}}</ref> since Version 4.0 from 7 February 2013.<br />
<br />
== Languages influenced by Python ==<br />
Python's design and philosophy have influenced many other programming languages:<br />
<br />
* [[Boo (programming language)|Boo]] uses indentation, a similar syntax, and a similar object model.<ref name="AutoNT-90" /><br />
* [[Cobra (programming language)|Cobra]] uses indentation and a similar syntax, and its "Acknowledgements" document lists Python first among languages that influenced it.<ref name="AutoNT-91" /> However, Cobra directly supports [[Design by contract|design-by-contract]], [[Unit testing|unit tests]], and optional [[static typing]].<ref name="AutoNT-92" /><br />
* [[CoffeeScript]], a [[programming language]] that cross-compiles to JavaScript, has Python-inspired syntax.<br />
* [[ECMAScript]] borrowed [[iterator]]s and [[generator (computer science)|generators]] from Python.<ref name="AutoNT-93" /><br />
* [[Go (programming language)|Go]] is designed for the "speed of working in a dynamic language like Python"<ref name="AutoNT-94"/> and shares the same syntax for slicing arrays.<br />
* [[Groovy (programming language)|Groovy]] was motivated by the desire to bring the Python design philosophy to [[Java (programming language)|Java]].<ref name="AutoNT-95" /><br />
* [[Julia (programming language)|Julia]] was designed "with [[hygienic macro|true macros]] [.. and to be] as usable for general programming as Python<!--, as easy for statistics as R, as natural for string processing as Perl, as powerful for linear algebra as Matlab, as good at gluing programs together as the shell. Something that is dirt simple to learn, yet keeps the most serious hackers happy. We want it interactive and we want it compiled.<br />
(Did we mention it --> [and] should be as fast as C<!--?-->".<ref name=Julia>{{cite web| title= Why We Created Julia| date= February 2012| website= Julia website| url= https://julialang.org/blog/2012/02/why-we-created-julia| accessdate= 5 June 2014}}</ref> Calling to or from Julia is possible; to with PyCall.jl and a Python package pyjulia allows calling, in the other direction, from Python.<br />
* [[Kotlin (programming language)|Kotlin]] is a functional programming language with an interactive shell similar to Python. However, Kotlin is statically typed with access to standard Java libraries.<ref>{{cite web|url=https://kotlinlang.org/docs/tutorials/command-line.html|title=Working with the Command Line Compiler - Kotlin Programming Language|website=Kotlin|accessdate=12 March 2018}}</ref><br />
* [[Nim (programming language)|Nim]] uses indentation and a similar syntax, however it is statically typed, and offers powerful macros.{{fact|date=February 2020}}<br />
* [[Ruby (programming language)|Ruby]]'s creator, [[Yukihiro Matsumoto]], has said: "I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language."<ref name="linuxdevcenter" /><br />
* [[Swift (programming language)|Swift]], a programming language developed by Apple, has some Python-inspired syntax.<ref>{{cite web |url=http://nondot.org/sabre |title=Chris Lattner's Homepage |publisher=Chris Lattner |first=Chris |last=Lattner |authorlink=Chris Lattner |date=3 June 2014 |accessdate=3 June 2014 |quote=I started work on the Swift Programming Language in July of 2010. I implemented much of the basic language structure, with only a few people knowing of its existence. A few other (amazing) people started contributing in earnest late in 2011, and it became a major focus for the Apple Developer Tools group in July 2013 [...] drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list.}}</ref><br />
* [[Gdscript|GDScript]], dynamically typed programming language used to create video-games. It is extremely similar to Python with a few minor differences.<br />
<br />
Python's development practices have also been emulated by other languages. For example, the practice of requiring a document describing the rationale for, and issues surrounding, a change to the language (in Python, a PEP) is also used in [[Tcl]]<ref name="AutoNT-99" /> and [[Erlang (programming language)|Erlang]].<ref name="AutoNT-100" /><br />
<br />
== See also ==<br />
{{Portal|Computer programming|Free and open-source software}}<br />
<br />
* [[Python syntax and semantics]]<br />
* [[pip (package manager)]]<br />
* [[IPython]]<br />
<br />
== References ==<br />
{{Reflist|30em|refs=<br />
<br />
<ref name="faq-created">{{cite web |url=https://docs.python.org/faq/general.html#why-was-python-created-in-the-first-place |title=Why was Python created in the first place? |work=General Python FAQ |publisher=Python Software Foundation |accessdate=22 March 2007}}</ref><br />
<br />
<ref name="98-interview">{{cite web |url=http://www.amk.ca/python/writing/gvr-interview |title=Interview with Guido van Rossum (July 1998) |last=Kuchling |first=Andrew M. |work=amk.ca |date=22 December 2006 |accessdate=12 March 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20070501105422/http://www.amk.ca/python/writing/gvr-interview |archivedate=1 May 2007 |df=dmy-all }}</ref><br />
<br />
<ref name="AutoNT-1">{{ cite journal |last=van Rossum |first=Guido |year=1993 |title=An Introduction to Python for UNIX/C Programmers |journal=Proceedings of the NLUUG Najaarsconferentie (Dutch UNIX Users Group) |quote=even though the design of C is far from ideal, its influence on Python is considerable. |citeseerx=10.1.1.38.2023 }}</ref><br />
<br />
<ref name="classmix">{{cite web |url=https://docs.python.org/tutorial/classes.html |title=Classes |work=The Python Tutorial |publisher=Python Software Foundation |accessdate=20 February 2012 |quote=It is a mixture of the class mechanisms found in C++ and Modula-3}}</ref><br />
<br />
<ref name="effbot-call-by-object">{{cite web |url=http://effbot.org/zone/call-by-object.htm |title=Call By Object |work=effbot.org |last=Lundh |first=Fredrik |quote=replace "CLU" with "Python", "record" with "instance", and "procedure" with "function or method", and you get a pretty accurate description of Python's object model. |accessdate=21 November 2017}}</ref><br />
<br />
<ref name="AutoNT-2">{{cite web |url=https://www.python.org/download/releases/2.3/mro/ |title=The Python 2.3 Method Resolution Order |last=Simionato |first=Michele |publisher=Python Software Foundation |quote=The C3 method itself has nothing to do with Python, since it was invented by people working on Dylan and it is described in a paper intended for lispers}}</ref><br />
<br />
<ref name="AutoNT-3">{{cite web |url=https://docs.python.org/howto/functional.html |title=Functional Programming HOWTO |last=Kuchling |first=A. M. |work=Python v2.7.2 documentation |publisher=Python Software Foundation |accessdate=9 February 2012}}</ref><br />
<br />
<ref name="pep0238">{{cite web |url=https://www.python.org/dev/peps/pep-0238/ |title=PEP 238&nbsp;– Changing the Division Operator |first1=Moshe |last1=Zadka |first2=Guido |last2=van Rossum |date=11 March 2001 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=23 October 2013}}</ref><br />
<br />
<ref name="AutoNT-4">{{cite web |url=https://www.python.org/dev/peps/pep-0255/ |title=PEP 255&nbsp;– Simple Generators |first1=Neil |last1=Schemenauer |first2=Tim |last2=Peters |first3=Magnus Lie |last3=Hetland |date=18 May 2001 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=9 February 2012}}</ref><br />
<br />
<ref name="AutoNT-5">{{cite web |url=https://www.python.org/dev/peps/pep-0318/ |title=PEP 318&nbsp;– Decorators for Functions and Methods |first1=Kevin D. |last1=Smith |first2=Jim J. |last2=Jewett |first3=Skip |last3=Montanaro |first4=Anthony |last4=Baxter |date=2 September 2004 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=24 February 2012}}</ref><br />
<br />
<ref name="AutoNT-6">{{cite web |url=https://docs.python.org/3.2/tutorial/controlflow.html |title=More Control Flow Tools |work=Python 3 documentation |publisher=Python Software Foundation |accessdate=24 July 2015}}</ref><br />
<br />
<ref name="bini">{{cite book |last=Bini |first=Ola |title=Practical JRuby on Rails Web 2.0 Projects: bringing Ruby on Rails to the Java platform |year=2007 |publisher=APress |location=Berkeley |isbn=978-1-59059-881-8 |page=[https://archive.org/details/practicaljrubyon0000bini/page/3 3] |url-access=registration |url=https://archive.org/details/practicaljrubyon0000bini/page/3 }}</ref><br />
<br />
<ref name="AutoNT-7">{{cite web |last=Kuhlman |first=Dave |url=https://www.davekuhlman.org/python_book_01.pdf|title=A Python Book: Beginning Python, Advanced Python, and Python Exercises |at=Section 1.1|url-status=dead |archiveurl=https://web.archive.org/web/20120623165941/http://cutter.rexx.com/~dkuhlman/python_book_01.html |archivedate=23 June 2012 |df=dmy-all }}</ref><br />
<br />
<ref name="About">{{cite web |url=https://www.python.org/about |title=About Python |publisher=Python Software Foundation |accessdate=24 April 2012}}, second section "Fans of Python use the phrase "batteries included" to describe the standard library, which covers everything from asynchronous processing to zip files."</ref><br />
<br />
<ref name="venners-interview-pt-1">{{cite web |url=http://www.artima.com/intv/pythonP.html |title=The Making of Python |last=Venners |first=Bill |date=13 January 2003 |work=Artima Developer |publisher=Artima |accessdate=22 March 2007}}</ref><br />
<br />
<ref name="timeline-of-python">{{cite web |url=https://python-history.blogspot.com/2009/01/brief-timeline-of-python.html <br />
|title=A Brief Timeline of Python |last=van Rossum |first=Guido |date=20 January 2009 |work=The History of Python |accessdate=20 January 2009}}</ref><br />
<br />
<ref name="AutoNT-12">{{ cite mailing list |url=https://mail.python.org/pipermail/python-dev/2000-August/008881.html |title=SETL (was: Lukewarm about range literals) |date=29 August 2000 |accessdate=13 March 2011 |mailinglist=Python-Dev |last=van Rossum |first=Guido |authorlink=Guido van Rossum}}</ref><br />
<br />
<ref name="newin-2.0">{{cite web |url=https://docs.python.org/whatsnew/2.0.html |title=What's New in Python 2.0 |last1=Kuchling |first1=A. M. |last2=Zadka |first2=Moshe |date=16 October 2000 |publisher=Python Software Foundation |accessdate=11 February 2012}}</ref><br />
<br />
<ref name="3.0-release">{{cite web |url=https://www.python.org/download/releases/3.0/ |title=Python 3.0 Release |publisher=Python Software Foundation |accessdate=8 July 2009}}</ref><br />
<br />
<ref name="pep-3000">{{cite web |url=https://www.python.org/dev/peps/pep-3000/ |title=PEP 3000&nbsp;– Python 3000 |last=van Rossum |first=Guido |date=5 April 2006 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=27 June 2009}}</ref><br />
<br />
<ref name="AutoNT-13">{{cite web |url=https://www.python.org/community/pycon/dc2004/papers/24/metaclasses-pycon.pdf |archiveurl=https://web.archive.org/web/20090530030205/http://www.python.org/community/pycon/dc2004/papers/24/metaclasses-pycon.pdf |archivedate=30 May 2009 |title=Python Metaclasses: Who? Why? When? |last=The Cain Gang Ltd. |accessdate=27 June 2009 |url-status=dead |df=dmy-all }}</ref><br />
<br />
<ref name="AutoNT-14">{{cite web |url=https://docs.python.org/3.0/reference/datamodel.html#special-method-names |title=3.3. Special method names |work=The Python Language Reference |publisher=Python Software Foundation |accessdate=27 June 2009}}</ref><br />
<br />
<ref name="AutoNT-15">{{cite web |url=http://www.nongnu.org/pydbc/ |title=PyDBC: method preconditions, method postconditions and class invariants for Python |accessdate=24 September 2011}}</ref><br />
<br />
<ref name="AutoNT-16">{{cite web |url=http://www.wayforward.net/pycontract/ |title=Contracts for Python |accessdate=24 September 2011}}</ref><br />
<br />
<ref name="AutoNT-17">{{cite web |url=https://sites.google.com/site/pydatalog/ |title=PyDatalog |accessdate=22 July 2012}}</ref><br />
<br />
<ref name="AutoNT-18">{{cite web |url=https://docs.python.org/3/library/itertools.html |title=6.5 itertools&nbsp;– Functions creating iterators for efficient looping |publisher=Docs.python.org |accessdate=22 November 2016}}</ref><br />
<br />
<ref name="PEP20">{{cite web |url=https://www.python.org/dev/peps/pep-0020/ |title=PEP 20&nbsp;– The Zen of Python |last=Peters |first=Tim |date=19 August 2004 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=24 November 2008}}</ref><br />
<br />
<ref name="AutoNT-19">{{cite book | url=http://shop.oreilly.com/product/9780596007973.do | title=Python Cookbook, 2nd Edition | publisher=[[O'Reilly Media]] |last1=Martelli |first1=Alex |last2=Ravenscroft |first2=Anna |last3=Ascher |first3=David | year=2005 | page=230 | isbn=978-0-596-00797-3}}</ref><br />
<br />
<ref name="AutoNT-20">{{cite web |url=http://ebeab.com/2014/01/21/python-culture/ |title=Python Culture}}</ref><br />
<br />
<ref name="PepCite000">{{cite web |url=https://www.python.org/dev/peps/pep-0001/ |title=PEP 1&nbsp;– PEP Purpose and Guidelines |last1=Warsaw |first1=Barry |last2=Hylton |first2=Jeremy |last3=Goodger |first3=David |date=13 June 2000 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=19 April 2011}}</ref><br />
<br />
<ref name="AutoNT-21">{{cite web |url=https://www.python.org/dev/intro/ |title=Guido, Some Guys, and a Mailing List: How Python is Developed |last=Cannon |first=Brett |work=python.org |publisher=Python Software Foundation |accessdate=27 June 2009 |url-status=dead |archiveurl=https://web.archive.org/web/20090601134342/http://www.python.org/dev/intro/ |archivedate=1 June 2009 }}</ref><br />
<br />
<ref name="release-schedule">{{cite web |url=https://mail.python.org/pipermail/python-dev/2002-April/022739.html |title=&#91;Python-Dev&#93; Release Schedules (was Stability & change) |last=Norwitz |first=Neal |date=8 April 2002 |accessdate=27 June 2009}}</ref><br />
<br />
<ref name="AutoNT-22">{{cite web |url=https://www.python.org/dev/peps/pep-0006/ |title=PEP 6&nbsp;– Bug Fix Releases |last1=Aahz |last2=Baxter |first2=Anthony |date=15 March 2001 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=27 June 2009}}</ref><br />
<br />
<ref name="AutoNT-23">{{cite web |url=https://www.python.org/dev/buildbot/ |title=Python Buildbot |work=Python Developer’s Guide |publisher=Python Software Foundation |accessdate=24 September 2011}}</ref><br />
<br />
<ref name="AutoNT-24">{{cite web |url=https://docs.python.org/2/faq/general.html#why-is-it-called-python |title=General Python FAQ |work=Python v2.7.3 documentation |publisher=Docs.python.org |date= |accessdate=3 December 2012}}</ref><br />
<br />
<ref name="tutorial-chapter1">{{cite web |url=https://docs.python.org/tutorial/appetite.html |title=Whetting Your Appetite |work=The Python Tutorial |publisher=Python Software Foundation |accessdate=20 February 2012}}</ref><br />
<br />
<ref name="AutoNT-25">{{cite web |url=http://python.net/crew/mwh/hacks/objectthink.html |title=How to think like a Pythonista}}</ref><br />
<br />
<ref name="AutoNT-26">{{cite web |url=https://stackoverflow.com/questions/5033906/in-python-should-i-use-else-after-a-return-in-an-if-block |title=In Python, should I use else after a return in an if block? |date=17 February 2011 |work=[[Stack Overflow]] |publisher=Stack Exchange |accessdate=6 May 2011}}</ref><br />
<br />
<ref name="AutoNT-27">{{cite web |url=http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html |title=Code Like a Pythonista: Idiomatic Python |last=Goodger |first=David}}</ref><br />
<br />
<ref name="AutoNT-28">{{cite web |url=http://page.mi.fu-berlin.de/prechelt/Biblio/jccpprt_computer2000.pdf |title=An empirical comparison of C, C++, Java, Perl, Python, Rexx, and Tcl |first=Lutz |last=Prechelt <!-- "work" doesn't work.. |work=[http://page.mi.fu-berlin.de/prechelt/Biblio/ Bibliography of Lutz Prechelt]--> |date=14 March 2000 |accessdate=30 August 2013}}</ref><br />
<br />
<ref name="quotes-about-python">{{cite web |url=https://www.python.org/about/quotes/ |title=Quotes about Python |publisher=Python Software Foundation |accessdate=8 January 2012}}</ref><br />
<br />
<ref name="AutoNT-29">{{cite web |url=https://wiki.python.org/moin/OrganizationsUsingPython |title=Organizations Using Python |publisher=Python Software Foundation |accessdate=15 January 2009}}</ref><br />
<br />
<ref name="AutoNT-30">{{ cite journal |title=Python : the holy grail of programming |journal=CERN Bulletin |issue=31/2006 |publisher=CERN Publications |date=31 July 2006 |url=http://cdsweb.cern.ch/journal/CERNBulletin/2006/31/News%20Articles/974627?ln=en |accessdate=11 February 2012}}</ref><br />
<br />
<ref name="AutoNT-31">{{cite web |url=https://www.python.org/about/success/usa/ |title=Python Streamlines Space Shuttle Mission Design |last=Shafer |first=Daniel G. |date=17 January 2003 |publisher=Python Software Foundation |accessdate=24 November 2008}}</ref><br />
<br />
<ref name="AutoNT-32">{{cite web |url=https://www.python.org/about/success/ilm/ |title=Industrial Light & Magic Runs on Python |last=Fortenberry |first=Tim |date=17 January 2003 |publisher=Python Software Foundation |accessdate=11 February 2012}}</ref><br />
<br />
<ref name="AutoNT-33">{{cite web |url=http://www.eweek.com/c/a/Application-Development/Python-Slithers-into-Systems/ |title=Python Slithers into Systems |last=Taft |first=Darryl K. |date=5 March 2007 |work=eWeek.com |publisher=Ziff Davis Holdings |accessdate=24 September 2011}}</ref><br />
<br />
<ref name="AutoNT-34">{{cite web |title=TIOBE Programming Community Index Python |author=TIOBE Software Index |year=2015 |url=http://www.tiobe.com/index.php/paperinfo/tpci/Python.html |accessdate=10 September 2015}}</ref><br />
<br />
<ref name="AutoNT-35">{{cite web |title=Usage statistics and market share of Python for websites |year=2012 |url=http://w3techs.com/technologies/details/pl-python/all/all |accessdate=18 December 2012}}</ref><br />
<br />
<ref name="AutoNT-38">{{cite web |url=http://www.jasc.com/support/customercare/articles/psp9components.asp |title=jasc psp9components |url-status=dead |archiveurl=https://web.archive.org/web/20080319061519/http://www.jasc.com/support/customercare/articles/psp9components.asp |archivedate=19 March 2008 }}</ref><br />
<br />
<ref name="AutoNT-39">{{cite web |url=http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=About_getting_started_with_writing_geoprocessing_scripts |title=About getting started with writing geoprocessing scripts |date=17 November 2006 |work=ArcGIS Desktop Help 9.2 |publisher=Environmental Systems Research Institute |accessdate=11 February 2012}}</ref><br />
<br />
<ref name="AutoNT-40">{{cite web |url=http://community.eveonline.com/news/dev-blogs/stackless-python-2.7/ |title=Stackless Python 2.7 |publisher=[[CCP Games]] |date=24 August 2010 |author=CCP porkbelly |work=EVE Community Dev Blogs |quote=As you may know, EVE has at its core the programming language known as Stackless Python.}}</ref><br />
<br />
<ref name="AutoNT-41">{{cite web |url=http://www.2kgames.com/civ4/blog_03.htm |title=Modding Sid Meier's Civilization IV |last=Caudill |first=Barry |date=20 September 2005 |publisher=[[Firaxis Games]] |archiveurl=https://web.archive.org/web/20101202164144/http://www.2kgames.com/civ4/blog_03.htm |archivedate=2 December 2010 |work=Sid Meier's Civilization IV Developer Blog |quote=we created three levels of tools ... The next level offers Python and XML support, letting modders with more experience manipulate the game world and everything in it. |url-status=dead |df=dmy-all }}</ref><br />
<br />
<ref name="AutoNT-42">{{cite web |url=https://code.google.com/apis/documents/docs/1.0/developers_guide_python.html |title=Python Language Guide (v1.0) |work=Google Documents List Data API v1.0 |archiveurl=https://web.archive.org/web/20100715145616/http://code.google.com/apis/documents/docs/1.0/developers_guide_python.html |archivedate=15 July 2010 |url-status=dead |df=dmy-all }}</ref><br />
<br />
<ref name="AutoNT-47">{{cite web |url=http://www.nltk.org |title=Natural Language Toolkit}}</ref><br />
<br />
<ref name="AutoNT-49">{{cite web |url=http://www.immunitysec.com/products-immdbg.shtml |title=Immunity: Knowing You're Secure |url-status=dead |archiveurl=https://web.archive.org/web/20090216134332/http://immunitysec.com/products-immdbg.shtml |archivedate=16 February 2009 |df=dmy-all }}</ref><br />
<br />
<ref name="AutoNT-50">{{cite web |url=http://oss.coresecurity.com/ |title=Corelabs site}}</ref><br />
<br />
<ref name="AutoNT-51">{{cite web |url=http://sugarlabs.org/go/Sugar |title=What is Sugar? |publisher=Sugar Labs |accessdate=11 February 2012}}</ref><br />
<br />
<ref name="AutoNT-52">{{cite web |title=Is Python a good language for beginning programmers? |url=https://docs.python.org/faq/general.html#is-python-a-good-language-for-beginning-programmers |work=General Python FAQ |publisher=Python Software Foundation |accessdate=21 March 2007}}</ref><br />
<br />
<ref name="AutoNT-53">{{cite web |url=http://www.secnetix.de/~olli/Python/block_indentation.hawk |title=Myths about indentation in Python |publisher=Secnetix.de |accessdate=19 April 2011}}</ref><br />
<br />
<!--ref name="AutoNT-54">{{cite web |url=http://c2.com/cgi/wiki?PythonWhiteSpaceDiscussion |title=White Space Discussion |accessdate=1 January 2013}}</ref--><br />
<br />
<ref name="AutoNT-55">{{cite web |last=van Rossum |first=Guido |url=http://neopythonic.blogspot.be/2009/04/tail-recursion-elimination.html |title=Tail Recursion Elimination |publisher=Neopythonic.blogspot.be |date=22 April 2009 |accessdate=3 December 2012}}</ref><br />
<br />
<ref name="AutoNT-56">{{cite web |title=Language Design Is Not Just Solving Puzzles |url=http://www.artima.com/weblogs/viewpost.jsp?thread=147358 |first=Guido |last=van Rossum |date=9 February 2006 |accessdate=21 March 2007 |work=Artima forums |publisher=Artima}}</ref><br />
<br />
<ref name="AutoNT-57">{{cite web |url=https://www.python.org/dev/peps/pep-0342/ |title=PEP 342&nbsp;– Coroutines via Enhanced Generators |last1=van Rossum |first1=Guido |last2=Eby |first2=Phillip J. |date=10 May 2005 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=19 February 2012}}</ref><br />
<br />
<ref name="AutoNT-58">{{cite web |url=https://www.python.org/dev/peps/pep-0380/ |title=PEP 380 |publisher=Python.org |date= |accessdate=3 December 2012}}</ref><br />
<br />
<ref name="AutoNT-59">{{cite web |url=https://www.python.org/dev/peps/pep-0289/ |title=PEP 289&nbsp;– Generator Expressions |last=Hettinger |first=Raymond |date=30 January 2002 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=19 February 2012}}</ref><br />
<br />
<ref name="AutoNT-60">{{cite web |url=https://www.python.org/dev/peps/pep-0308/ |title=PEP 308&nbsp;– Conditional Expressions |last1=van Rossum |first1=Guido |last2=Hettinger |first2=Raymond |date=7 February 2003 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=13 July 2011}}</ref><br />
<br />
<ref name="AutoNT-61">{{cite web |url=https://docs.python.org/faq/design.html#why-must-self-be-used-explicitly-in-method-definitions-and-calls |title=Why must 'self' be used explicitly in method definitions and calls? |work=Design and History FAQ |publisher=Python Software Foundation |accessdate=19 February 2012}}</ref><br />
<br />
<ref name="classy">{{cite web |title=The Python Language Reference, section 3.3. New-style and classic classes, for release 2.7.1 |accessdate=12 January 2011 |url=https://docs.python.org/reference/datamodel.html#new-style-and-classic-classes}}</ref><br />
<br />
<ref name="pep0237">{{cite web |url=https://www.python.org/dev/peps/pep-0237/ |title=PEP 237&nbsp;– Unifying Long Integers and Integers |last1=Zadka |first1=Moshe |last2=van Rossum |first2=Guido |date=11 March 2001 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=24 September 2011}}</ref><br />
<br />
<ref name="AutoNT-62">{{cite web |url=https://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html |title=Why Python's Integer Division Floors |accessdate=25 August 2010}}</ref><br />
<br />
<ref name="AutoNT-63">{{citation |url=https://docs.python.org/library/functions.html#round |accessdate=14 August 2011 |title=round |work=The Python standard library, release 2.7, §2: Built-in functions}}</ref><br />
<br />
<ref name="AutoNT-64">{{citation |url=https://docs.python.org/py3k/library/functions.html#round |accessdate=14 August 2011 |title=round |work=The Python standard library, release 3.2, §2: Built-in functions}}</ref><br />
<br />
<ref name="AutoNT-65">{{cite book | title=Python Essential Reference | first1=David M. |last1=Beazley | edition=4th | year = 2009 | page =66 }}</ref><br />
<br />
<ref name="CPL">{{cite book | title=The C Programming Language | first1=Brian W. | last1=Kernighan | first2=Dennis M. | last2=Ritchie |titlelink=The C Programming Language | edition=2nd | year=1988 | page=[https://archive.org/details/cprogramminglang00bria/page/206 206] }}</ref><br />
<br />
<ref name="AutoNT-66">{{cite web |url=https://www.python.org/dev/peps/pep-0007/ |title=PEP 7&nbsp;– Style Guide for C Code |last=van Rossum |first=Guido |date=5 June 2001 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=24 November 2008}}</ref><br />
<br />
<ref name="AutoNT-67">{{cite web |url=https://docs.python.org/3/library/dis.html#python-bytecode-instructions |title=CPython byte code |publisher=Docs.python.org |accessdate=16 February 2016}}</ref><br />
<br />
<ref name="AutoNT-68">{{cite web |url=http://www.troeger.eu/teaching/pythonvm08.pdf |title=Python 2.5 internals |accessdate=19 April 2011}}</ref><br />
<br />
<ref name="AutoNT-69">{{cite web |url=http://www.oreilly.com/pub/a/oreilly/frank/rossum_1099.html |title=An Interview with Guido van Rossum |publisher=Oreilly.com |accessdate=24 November 2008}}</ref><br />
<br />
<ref name="AutoNT-70">{{cite web |url=https://pypy.org/compat.html |title=PyPy compatibility |publisher=Pypy.org |date= |accessdate=3 December 2012}}</ref><br />
<br />
<ref name="AutoNT-71">{{cite web |url=http://speed.pypy.org/ |title=speed comparison between CPython and Pypy |publisher=Speed.pypy.org |date= |accessdate=3 December 2012}}</ref><br />
<br />
<ref name="AutoNT-73">{{cite web |url=http://doc.pypy.org/en/latest/stackless.html |title=Application-level Stackless features — PyPy 2.0.2 documentation |publisher=Doc.pypy.org |accessdate=17 July 2013}}</ref><br />
<br />
<ref name="AutoNT-74">{{cite web |url=https://code.google.com/p/unladen-swallow/wiki/ProjectPlan |title=Plans for optimizing Python |work=Google Project Hosting |date=15 December 2009 |accessdate=24 September 2011}}</ref><br />
<br />
<ref name="AutoNT-86">{{cite web |first=Przemyslaw |last=Piotrowski |url=http://www.oracle.com/technetwork/articles/piotrowski-pythoncore-084049.html |title=Build a Rapid Web Development Environment for Python Server Pages and Oracle |work=Oracle Technology Network |publisher=Oracle |date=July 2006 |accessdate=12 March 2012}}</ref><br />
<br />
<ref name="AutoNT-88">{{cite web |url=https://www.python.org/dev/peps/pep-0327/ |title=PEP 327&nbsp;– Decimal Data Type |last=Batista |first=Facundo |date=17 October 2003 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=24 November 2008}}</ref><br />
<br />
<ref name="AutoNT-89">{{cite web |url=https://www.python.org/dev/peps/pep-0333/ |title=PEP 333&nbsp;– Python Web Server Gateway Interface v1.0 |last=Eby |first=Phillip J. |date=7 December 2003 |work=Python Enhancement Proposals |publisher=Python Software Foundation |accessdate=19 February 2012}}</ref><br />
<br />
<ref name="AutoNT-90">{{cite web |url=http://boo.codehaus.org/Gotchas+for+Python+Users |title=Gotchas for Python Users |work=boo.codehaus.org |publisher=Codehaus Foundation |accessdate=24 November 2008 |url-status=dead |archiveurl=https://web.archive.org/web/20081211062108/http://boo.codehaus.org/Gotchas+for+Python+Users |archivedate=11 December 2008 |df=dmy-all }}</ref><br />
<br />
<ref name="AutoNT-91">{{cite web |url=http://cobra-language.com/docs/acknowledgements/ |title=Acknowledgements |last=Esterbrook |first=Charles |work=cobra-language.com |publisher=Cobra Language |accessdate=7 April 2010}}</ref><br />
<br />
<ref name="AutoNT-92">{{cite web |url=http://cobra-language.com/docs/python/ |title=Comparison to Python |last=Esterbrook |first=Charles |work=cobra-language.com |publisher=Cobra Language |accessdate=7 April 2010}}</ref><br />
<br />
<ref name="AutoNT-93">{{cite web |url=http://wiki.ecmascript.org/doku.php?id=proposals:iterators_and_generators |archive-url=https://web.archive.org/web/20071020082650/http://wiki.ecmascript.org/doku.php?id=proposals:iterators_and_generators |url-status=dead |archive-date=20 October 2007 |title=Proposals: iterators and generators [ES4 Wiki&#93; |publisher=wiki.ecmascript.org |accessdate=24 November 2008 }}</ref><br />
<br />
<ref name="AutoNT-94">{{cite news |url=https://techcrunch.com/2009/11/10/google-go-language/ |title=Google's Go: A New Programming Language That's Python Meets C++ |last=Kincaid |first=Jason |date=10 November 2009 |work=TechCrunch |accessdate=29 January 2010}}</ref><br />
<br />
<ref name="AutoNT-95">{{cite web |last=Strachan |first=James |date=29 August 2003 |title=Groovy&nbsp;– the birth of a new dynamic language for the Java platform |url=http://radio.weblogs.com/0112098/2003/08/29.html}}</ref><br />
<br />
<ref name="linuxdevcenter">{{cite web |url=http://www.linuxdevcenter.com/pub/a/linux/2001/11/29/ruby.html |title=An Interview with the Creator of Ruby |publisher=Linuxdevcenter.com |date= |accessdate=3 December 2012}}</ref><br />
<br />
<ref name="AutoNT-99">{{cite web |url=http://www.tcl.tk/cgi-bin/tct/tip/3.html |title=TIP #3: TIP Format |last1=Kupries |first1=Andreas |last2=Fellows |first2=Donal K. |work=tcl.tk |publisher=Tcl Developer Xchange |date=14 September 2000 |accessdate=24 November 2008}}</ref><br />
<br />
<ref name="AutoNT-100">{{cite web |url=http://www.erlang.org/eeps/eep-0001.html |title=EEP 1: EEP Purpose and Guidelines |last1=Gustafsson |first1=Per |last2=Niskanen |first2=Raimo |publisher=erlang.org |date=29 January 2007 |accessdate=19 April 2011}}</ref><br />
<br />
<!-- <ref name="AutoNT-101">{{cite web |url=http://www.tiobe.com/index.php/content/paperinfo/tpci/ |title=TIOBE Programming Community Index for March 2012 |date=March 2012 |publisher=TIOBE Software |accessdate=25 March 2012}}</ref>--><br />
<br />
<ref name="lj-bdfl-resignation">{{cite magazine |url=https://www.linuxjournal.com/content/guido-van-rossum-stepping-down-role-pythons-benevolent-dictator-life |title=Guido van Rossum Stepping Down from Role as Python's Benevolent Dictator For Life |last=Fairchild |first=Carlie |magazine=Linux Journal |date=12 July 2018 |accessdate=13 July 2018}}</ref><br />
<br />
}}<br />
<br />
===Sources===<br />
*{{cite web |url=https://wiki.python.org/moin/PythonForArtificialIntelligence |title=Python for Artificial Intelligence |publisher=Wiki.python.org |date=19 July 2012 |accessdate=3 December 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20121101045354/http://wiki.python.org/moin/PythonForArtificialIntelligence |archivedate=1 November 2012 }}<br />
*{{cite journal |editor-last=Paine |editor-first=Jocelyn |title=AI in Python |journal=AI Expert Newsletter |publisher=Amzi! |date=August 2005 |url=http://www.ainewsletter.com/newsletters/aix_0508.htm#python_ai_ai |accessdate=11 February 2012}}<br />
*{{cite web |url=https://pypi.python.org/pypi/PyAIML |title=PyAIML 0.8.5 : Python Package Index |publisher=Pypi.python.org |accessdate=17 July 2013}}<br />
*{{cite book |title=Artificial Intelligence: A Modern Approach |last1=Russell |first1=Stuart J. |authorlink1=Stuart J. Russell |last2=Norvig |first2=Peter |authorlink2=Peter Norvig |lastauthoramp=y |edition=3rd |year=2009 |publisher=Prentice Hall |location=Upper Saddle River, NJ |isbn=978-0-13-604259-4 }}<br />
<br />
== Further reading ==<br />
<!-- THIS IS *NOT* A LIST OF ALL PYTHON BOOKS<br />
According to [[Wikipedia:Further reading]], criteria for inclusion includes:<br />
1. Should clearly qualify as WP:RS, as indicated by reviews and citations to it.<br />
...<br />
5. There should be guidelines on limiting the number of sources.<br />
6. To avoid spam, any book included should have received more than one good review in RS: newspapers and scholarly journals being the norm, and the clear balance of RS reviews should be positive. This would avoid self-publish spamming, POV pushing, and attempts by publishers to get books promoted through inclusion on Wikipedia. At the moment "editorial recommendations" as described in the manual smacks of OR.<br />
7. Neutrality on the part of editors is essential. In terms of major debates, items representing all major positions should be included, with annotations indicating the specific POV of each. We may have to work out rules where topic disputes are irreconcilable.<br />
--><br />
<br />
* {{cite book |last=Downey |first=Allen B. |title=Think Python: How to Think Like a Computer Scientist |edition=Version 1.6.6 |date=May 2012 |isbn=978-0-521-72596-5 }}<br />
* {{cite news |url=http://www.computerworld.com.au/index.php/id;66665771 |title=The A-Z of Programming Languages: Python |last=Hamilton |first=Naomi |date=5 August 2008 |work=Computerworld |accessdate=31 March 2010 |url-status=dead |archiveurl=https://web.archive.org/web/20081229095320/http://www.computerworld.com.au/index.php/id%3B66665771 |archivedate=29 December 2008 |df=dmy-all }}<br />
* {{cite book |last=Lutz |first=Mark |title=Learning Python |publisher=O'Reilly Media |year=2013 |edition=5th |isbn=978-0-596-15806-4 }}<br />
* {{cite book |last=Pilgrim |first=Mark |title=Dive Into Python |publisher=Apress |year=2004 |isbn=978-1-59059-356-1 |url-access=registration |url=https://archive.org/details/diveintopython0000pilg }}<br />
* {{cite book |last=Pilgrim |first=Mark |title=Dive Into Python 3 |publisher=Apress |year=2009 |isbn=978-1-4302-2415-0 }}<br />
* {{cite book |last=Summerfield |first=Mark |title=Programming in Python 3 |publisher=Addison-Wesley Professional|year=2009|edition=2nd|isbn=978-0-321-68056-3 }}<br />
<br />
== External links ==<br />
<!-- ===================== {{No more links}} =========================<br />
| PLEASE BE CAUTIOUS IN ADDING MORE LINKS TO THIS ARTICLE. Wikipedia |<br />
| is not a collection of links nor should it be used for advertising. |<br />
| |<br />
| Excessive or inappropriate links WILL BE DELETED. |<br />
| See [[Wikipedia:External links]] & [[Wikipedia:Spam]] for details. |<br />
| |<br />
| If there are already plentiful links, please propose additions or |<br />
| replacements on this article's discussion page, or submit your link |<br />
| to the relevant category at the Open Directory Project (dmoz.org) |<br />
| and link back to that category using the {{Dmoz}} template. |<br />
========================== {{No more links}} ====================== --><br />
<br />
{{Sister project links |wikt=no |commons=Category:Python (programming language) |b=Python Programming |n=no |s=no |voy=no |species=no |d=no }}<br />
* {{Official website}}<br />
* {{Curlie|Computers/Programming/Languages/Python}}<br />
<br />
{{Programming languages}}<br />
{{Python (programming language)}}<br />
{{Python web frameworks}}<br />
{{FOSS}}<br />
<br />
{{Authority control}}<br />
{{Good article}}<br />
<br />
[[Category:Programming languages]]<br />
[[Category:Class-based programming languages]]<br />
[[Category:Computational notebook]]<br />
[[Category:Computer science in the Netherlands]]<br />
[[Category:Cross-platform free software]]<br />
[[Category:Dutch inventions]]<br />
[[Category:Dynamically typed programming languages]]<br />
[[Category:Educational programming languages]]<br />
[[Category:High-level programming languages]]<br />
[[Category:Information technology in the Netherlands]]<br />
[[Category:Multi-paradigm programming languages]]<br />
[[Category:Object-oriented programming languages]]<br />
[[Category:Programming languages created in 1991]]<br />
[[Category:Python (programming language)| ]]<br />
[[Category:Scripting languages]]<br />
[[Category:Text-oriented programming languages]]<br />
[[Category:Cross-platform software]]<br />
[[Category:Articles with example Python code]]</div>C++ Trolling Algorithmhttps://en.wikipedia.org/w/index.php?title=C%2B%2B&diff=943900468C++2020-03-04T14:18:03Z<p>C++ Trolling Algorithm: </p>
<hr />
<div>{{Redirect|CXX|the Roman numerals|120 (number)}}<br />
{{pp-move-vandalism|small=yes}}<br />
{{short description|General-purpose programming language}}<br />
{{Use dmy dates|date=January 2020 }}<br />
<br />
{{Infobox programming language<br />
| name = C++<br />
| logo = File:ISO C++ Logo.svg<br />
| logo caption = The C++ logo endorsed by Standard C++<br />
| logo size = 150px<br />
| paradigms = [[Multi-paradigm programming language|Multi-paradigm]]: [[procedural programming|procedural]], [[functional programming|functional]], [[object-oriented programming|object-oriented]], [[generic programming|generic]]<br />
| family = [[C (programming language)|C]]<br />
| designer = [[Bjarne Stroustrup]]<br />
| developer = ISO/IEC JTC1 (Joint Technical Committee 1) / SC22 (Subcommittee 22) / WG21 (Working Group 21)<br />
| released = {{Start date and age|df=yes|1985}}<br />
| latest release version = C++17 {{Small|(ISO/IEC 14882:2017)}}<br />
| latest release date = {{Start date and age|2017|12|01|df=yes}}<br />
| latest preview version = C++20<br />
| latest preview date = <br />
| typing = [[Static type|Static]], [[Nominal type system|nominative]], [[Type inference|partially inferred]]<br />
| scope = <br />
| platform = <br />
| operating system = <br />
| file ext = .C, .cc, .cpp, .cxx, {{nowrap|.c++}}, .h, .hh, .hpp, .hxx, {{nowrap|.h++}}<br />
| file format = <br />
| implementations = {{nowraplinks|[[Clang|LLVM Clang]], [[GNU Compiler Collection|GCC]], [[Microsoft Visual C++]], [[C++Builder|Embarcadero C++Builder]], [[Intel C++ Compiler]], [[IBM XL C++]], [[Edison Design Group|EDG]]}}<br />
| dialects = <br />
| influenced by = [[Ada (programming language)|Ada]], [[ALGOL 68]], [[C (programming language)|C]], [[CLU (programming language)|CLU]], [[ML (programming language)|ML]], [[Simula]]<br />
| influenced = [[Ada (programming language)|Ada 95]]<!-- 1995 -->, [[C Sharp (programming language)|C#]]<!-- 2001 -->,<ref name="influenceSharp">{{cite journal |last=Naugler |first=David |date=May 2007 |title=C# 2.0 for C++ and Java programmer: conference workshop |journal=Journal of Computing Sciences in Colleges |volume=22 |issue=5 |quote=Although C# has been strongly influenced by Java it has also been strongly influenced by C++ and is best viewed as a descendant of both C++ and Java.}}</ref> [[C99]]<!-- 1999 -->, [[Chapel (programming language)|Chapel]],<ref name="chplspec">{{cite web|title=Chapel spec (Acknowledgements)|url=https://chapel-lang.org/spec/spec-0.98.pdf|date=1 October 2015|accessdate=14 January 2016|publisher=Cray Inc}}</ref> [[Clojure]],<ref>{{cite web |url=http://www.codequarterly.com/2011/rich-hickey/ |archive-url=https://web.archive.org/web/20170111184835/http://www.codequarterly.com/2011/rich-hickey/ |url-status=dead |archive-date=2017-01-11 |title=Rich Hickey Q&A by Michael Fogus |access-date=2017-01-11}}</ref> [[D (programming language)|D]]<!-- 1999 -->, [[Java (programming language)|Java]]<!-- 1995 -->,<ref>{{cite web | url=https://books.google.com/books?id=0rUtBAAAQBAJ&lpg=PA133&pg=PA133#v=onepage&q&f=true|title=Cracking The Java Programming Interview :: 2000+ Java Interview Que/Ans |author=Harry. H. Chaudhary |accessdate=29 May 2016 |date=28 July 2014}}</ref> [[Lua (programming language)|Lua]]<!-- 1993 -->, [[Nim (programming language)|Nim]],{{citation needed|date=April 2017}} [[Perl]]<!-- 1987 -->, [[PHP]]<!-- 1995 -->, [[Python (programming language)|Python]],<ref>{{Cite web|url=https://docs.python.org/tutorial/classes.html|title=9. Classes — Python 3.6.4 documentation|website=docs.python.org|access-date=2018-01-09}}</ref> [[Rust (programming language)|Rust]], [[Seed7]]<br />
| wikibooks = C++ Programming<br />
}}<br />
<br />
A simple C++ Program:<br />
<br />
// A c++ program to vandalise wikipedia.<br />
* #include<iostream><br />
* #include <string><br />
<br />
* using namespace std;<br />
* int main(){<br />
* cout << "Fuierdai \n";<br />
* cout << "Willy on Wheels";<br />
* return 0;<br />
* }<br />
c<br />
'''C++''' ({{IPAc-en|ˌ|s|iː|ˌ|p|l|ʌ|s|ˈ|p|l|ʌ|s}}<!-- "cee" is the name of letter "c" -->) is a [[High-level programming language|high-level]], [[general-purpose programming language]] created by [[Bjarne Stroustrup]] as an extension of the [[C (programming language)|C programming language]], or "C with [[Class (programming)|Classes]]". The language has expanded significantly over time, and modern C++ has [[object-oriented programming|object-oriented]], [[generic programming|generic]], and [[functional programming|functional]] features in addition to facilities for [[Low-level programming language|low-level]] [[Memory (computing)|memory]] manipulation. It is almost always implemented as a [[compiled language]], and many vendors provide [[List of compilers#C.2B.2B compilers|C++ compilers]], including the [[Free Software Foundation]], [[LLVM]], [[Microsoft]], [[Intel]], [[Oracle Developer Studio|Oracle]], and [[IBM]], so it is available on many platforms.<ref name="stroustruptcpppl">{{Cite book |last=Stroustrup |first=Bjarne |authorlink=Bjarne Stroustrup |title=The C++ Programming Language |year=1997 |edition=Third |chapter=1 |isbn=0-201-88954-4 |oclc=59193992 |url=https://archive.org/details/cprogramminglang00stro_0 }}</ref><br />
<br />
C++ was designed with a bias toward [[system programming]] and [[embedded software|embedded]], resource-constrained software and large systems, with [[performance (software)|performance]], efficiency, and flexibility of use as its design highlights.<ref name=Stroustrup1>{{cite web|url=https://www.youtube.com/watch?v=86xWVb4XIyE|author=Stroustrup, B.|title=Lecture:The essence of C++. University of Edinburgh. |date=6 May 2014|accessdate=12 June 2015}}</ref> C++ has also been found useful in many other contexts, with key strengths being software infrastructure and resource-constrained applications,<ref name=Stroustrup1 /> including [[application software|desktop applications]], [[video games]], [[Server (computing)|servers]] (e.g. [[e-commerce]], [[Web search engine|Web search]], or [[SQL]] servers), and performance-critical applications (e.g. [[telephone switches]] or [[space probes]]).<ref name="applications">{{cite web |url=http://www.stroustrup.com/applications.html |title=C++ Applications |date=17 February 2014 |accessdate=5 May 2014 |first=Bjarne |last=Stroustrup |website=stroustrup.com}}</ref><br />
<br />
C++ is standardized by the [[International Organization for Standardization]] (ISO), with the latest standard version ratified and published by ISO in December 2017 as [[#Standardization|''ISO/IEC 14882:2017'']] (informally known as [[C++17]]).<ref name="isocpp2017"/> The C++ programming language was initially standardized in 1998 as ''ISO/IEC 14882:1998'', which was then amended by the [[C++03]], [[C++11]] and [[C++14]] standards. The current C++17 standard supersedes these with new features and an enlarged [[#Standard library|standard library]]. Before the initial standardization in 1998, C++ was developed by Danish computer scientist [[Bjarne Stroustrup]] at [[Bell Labs]] since 1979 as an extension of the [[C (programming language)|C language]]; he wanted an efficient and flexible language similar to C that also provided [[High-level programming language|high-level features]] for program organization.<ref>{{cite web |title=Bjarne Stroustrup's Homepage |url=http://www.stroustrup.com |website=www.stroustrup.com}}</ref> [[C++20]] is the next planned standard, keeping with the current trend of a new version every three years.<ref>{{cite web |title = C++; Where it's heading |url=https://dzone.com/articles/c-where-is-it-heading-and-what-are-the-new-feature}}</ref><br />
<br />
== History ==<br />
[[File:BjarneStroustrup.jpg|thumb|Bjarne Stroustrup, the creator of C++, in his AT&T New Jersey office c. 2000]]<br />
<br />
In 1979, [[Bjarne Stroustrup]], a Danish [[computer scientist]], began work on "{{visible anchor|C with [[Class (computer programming)|Classes]]}}", the predecessor to C++.<ref name="invention3">{{cite web |url = http://www.stroustrup.com/bs_faq.html#invention|title = Bjarne Stroustrup's FAQ: When was C++ invented?|first = Bjarne|last = Stroustrup|website = stroustrup.com|date = 7 March 2010|accessdate = 16 September 2010}}<br />
</ref> The motivation for creating a new language originated from Stroustrup's experience in programming for his PhD thesis. Stroustrup found that [[Simula]] had features that were very helpful for large software development, but the language was too slow for practical use, while [[BCPL]] was fast but too low-level to be suitable for large software development. When Stroustrup started working in [[AT&T Bell Labs]], he had the problem of analyzing the [[Unix|UNIX]] [[Kernel (computer science)|kernel]] with respect to [[distributed computing]]. Remembering his Ph.D. experience, Stroustrup set out to enhance the [[C (programming language)|C]] language with [[Simula]]-like features.<ref name="evolving">{{cite web |url = http://stroustrup.com/hopl-almost-final.pdf|title = Evolving a language in and for the real world: C++ 1991-2006|first = Bjarne|last = Stroustrup}}<br />
</ref> C was chosen because it was general-purpose, fast, portable and widely used. As well as C and Simula's influences, other languages also influenced this new language, including [[ALGOL 68]], [[Ada (programming language)|Ada]], [[CLU (programming language)|CLU]] and [[ML (programming language)|ML]].<br />
<br />
Initially, Stroustrup's "C with Classes" added features to the C compiler, Cpre, including [[class (computer programming)|classes]], [[derived class]]es, [[strong typing]], [[inlining]] and [[default argument]]s.<ref name="hopl2">{{cite web|last1=Stroustrup|first1=Bjarne|title=A History of C ++ : 1979− 1991|url=http://www.stroustrup.com/hopl2.pdf}}</ref><br />
<br />
In 1982, Stroustrup started to develop a successor to C with Classes, which he named "C++" (<syntaxhighlight lang="C++" inline>++</syntaxhighlight> being the [[increment operator]] in C) after going through several other names. New features were added, including [[virtual function]]s, function name and [[operator overloading]], references, constants, type-safe free-store memory allocation (new/delete), improved type checking, and BCPL style single-line comments with two forward slashes (<syntaxhighlight lang="C++" inline>//</syntaxhighlight>). Furthermore, Stroustrup developed a new, standalone compiler for C++, [[Cfront]].<br />
<br />
In 1985, the first edition of ''[[The C++ Programming Language]]'' was released, which became the definitive reference for the language, as there was not yet an official standard.<ref name="1st-edition3">{{cite web |url = http://www.stroustrup.com/1st.html|title = The C++ Programming Language|edition = First|first = Bjarne|last = Stroustrup|accessdate = 16 September 2010}}<br />
</ref> The first commercial implementation of C++ was released in October of the same year.<ref name="invention3"/><br />
<br />
In 1989, C++ 2.0 was released, followed by the updated second edition of ''The C++ Programming Language'' in 1991.<ref name="2nd-edition3">{{cite web |url = http://www.stroustrup.com/2nd.html|title = The C++ Programming Language|edition = Second|first = Bjarne|last = Stroustrup|accessdate = 16 September 2010}}</ref> New features in 2.0 included multiple inheritance, abstract classes, static member functions, [[const correctness|const member functions]], and protected members. In 1990, ''The Annotated C++ Reference Manual'' was published. This work became the basis for the future standard. Later feature additions included [[template (programming)|template]]s, [[exception handling|exceptions]], [[namespaces]], new [[cast (computer science)|cast]]s, and a [[Boolean datatype|Boolean type]].<br />
<br />
[[Image:20160121 CppFRUG Joel Falcou CppQuiz 3.jpg|thumb|left|A quiz on C++11 features being given in Paris in 2015]]<br />
<br />
In 1998, C++98 was released, standardizing the language, and a minor update ([[C++03]]) was released in 2003.<br />
<br />
After C++98, C++ evolved relatively slowly until, in 2011, the [[C++11]] standard was released, adding numerous new features, enlarging the standard library further, and providing more facilities to C++ programmers. After a minor [[C++14]] update released in December 2014, various new additions were introduced in [[C++17]], and further changes planned for 2020.<ref name="herbsutter.com">https://herbsutter.com/2016/06/30/trip-report-summer-iso-c-standards-meeting-oulu/ "the next standard after C++17 will be C++20"</ref><br />
<br />
As of 2019, C++ is now the fourth most popular programming language, behind [[Java (programming language)|Java]], C, and [[Python (programming language) |Python]].<ref>"Latest news." TIOBE Index | TIOBE - The Software Quality Company. N.p., n.d. Web. 5 June 2017.</ref><ref>Krill, Paul. "Java, C, C face growing competition in popularity." InfoWorld. InfoWorld, 10 February 2017. Web. 5 June 2017.</ref><br />
<br />
On January 3, 2018, Stroustrup was announced as the 2018 winner of the [[Charles Stark Draper Prize]] for Engineering, "for conceptualizing and developing the C++ programming language".<ref>https://www.nae.edu/177355.aspx "Computer Science Pioneer Bjarne Stroustrup to Receive the 2018 Charles Stark Draper Prize for Engineering"</ref><br />
{{clear}}<br />
<br />
=== Etymology ===<br />
According to Stroustrup, "the name signifies the evolutionary nature of the changes from C".<ref name="name">{{cite web |url=http://www.stroustrup.com/bs_faq.html#name |title=Bjarne Stroustrup's FAQ&nbsp;– Where did the name "C++" come from? |accessdate=16 January 2008 }}</ref> This name is credited to Rick Mascitti (mid-1983)<ref name="hopl2" /> and was first used in December 1983. When Mascitti was questioned informally in 1992 about the naming, he indicated that it was given in a [[tongue-in-cheek]] spirit. The name comes from C's <syntaxhighlight lang="C++" inline>++</syntaxhighlight> [[operator (programming)|operator]] (which [[increment and decrement operators|increments]] the [[value (computer science)|value]] of a [[variable (programming)|variable]]) and a common [[naming convention]] of using "+" to indicate an enhanced computer program.<br />
<br />
During C++'s development period, the language had been referred to as "new C" and "C with Classes"<ref name="hopl2" /><ref>{{cite web|title=C For C++ Programmers|url=https://www.ccs.neu.edu/course/com3620/parent/C-for-Java-C++/c-for-c++-alt.html|publisher=[[Northeastern University]]|accessdate=7 September 2015|archive-url=https://web.archive.org/web/20101117003419/http://www.ccs.neu.edu/course/com3620/parent/C-for-Java-C++/c-for-c++-alt.html|archive-date=17 November 2010|url-status=dead|df=dmy-all}}</ref> before acquiring its final name.<br />
<br />
=== Philosophy ===<br />
Throughout C++'s life, its development and evolution has been guided by a set of principles:<ref name="evolving"/><br />
<br />
* It must be driven by actual problems and its features should be immediately useful in real world programs.<br />
* Every feature should be implementable (with a reasonably obvious way to do so).<br />
* Programmers should be free to pick their own programming style, and that style should be fully supported by C++.<br />
* Allowing a useful feature is more important than preventing every possible misuse of C++.<br />
* It should provide facilities for organising programs into separate, well-defined parts, and provide facilities for combining separately developed parts.<br />
* No implicit violations of the [[type system]] (but allow explicit violations; that is, those explicitly requested by the programmer).<br />
* User-created types need to have the same support and performance as built-in types.<br />
* Unused features should not negatively impact created executables (e.g. in lower performance).<br />
* There should be no language beneath C++ (except [[assembly language]]).<br />
* C++ should work alongside other existing [[programming language]]s, rather than fostering its own separate and incompatible [[programming environment]].<br />
* If the programmer's intent is unknown, allow the programmer to specify it by providing manual control.<br />
<br />
=== Standardization ===<br />
[[Image:C++ Standards Committee meeting - July 1996 Stockholm - Wednesday general session.jpg|thumb|left|Scene during the C++ Standards Committee meeting in Stockholm in 1996]]<br />
{| class="wikitable floatright" style="margin-left: 1.5em;"<br />
|-<br />
! Year !! C++ Standard !! Informal name<br />
|-<br />
! 1998<br />
| | ISO/IEC 14882:1998<ref name="isocpp1998">{{cite web |title=ISO/IEC 14882:1998|publisher=International Organization for Standardization|url=https://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=25845 }}</ref> || C++98<br />
|-<br />
! 2003<br />
| | ISO/IEC 14882:2003<ref name="isocpp2003">{{cite web |title=ISO/IEC 14882:2003|publisher=International Organization for Standardization|url=https://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=38110 }}</ref> || [[C++03]]<br />
|-<br />
! 2011<br />
| | ISO/IEC 14882:2011<ref name="isocpp2011">{{cite web |title=ISO/IEC 14882:2011|publisher=International Organization for Standardization|url=https://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=50372 }}</ref> || [[C++11]], C++0x<br />
|-<br />
! 2014<br />
| | ISO/IEC 14882:2014<ref name="isocpp2014">{{cite web |title=ISO/IEC 14882:2014|publisher=International Organization for Standardization|url=https://www.iso.org/iso/home/store/catalogue_ics/catalogue_detail_ics.htm?csnumber=64029&ICS1=35&ICS2=60 }}</ref> || [[C++14]], C++1y<br />
|-<br />
! 2017<br />
| | ISO/IEC 14882:2017<ref name="isocpp2017">{{cite web |title=ISO/IEC 14882:2017|publisher=International Organization for Standardization|url=https://www.iso.org/standard/68564.html}}</ref> || [[C++17]], C++1z<br />
|-<br />
! 2020<br />
| | to be determined || [[C++20]],<ref name="herbsutter.com"/> C++2a<br />
|}<br />
<br />
C++ is standardized by an [[International Organization for Standardization|ISO]] working group known as [[ISO/IEC JTC 1/SC 22|JTC1/SC22/WG21]]. So far, it has published five revisions of the C++ standard and is currently working on the next revision, [[C++20]].<br />
<br />
In 1998, the ISO working group standardized C++ for the first time as ''ISO/IEC 14882:1998'', which is informally known as ''C++98''. In 2003, it published a new version of the C++ standard called ''ISO/IEC 14882:2003'', which fixed problems identified in C++98.<br />
<br />
The next major revision of the standard was informally referred to as "C++0x", but it was not released until 2011.<ref name="0xapprove">{{cite web|url=https://herbsutter.com/2011/08/12/we-have-an-international-standard-c0x-is-unanimously-approved/|title=We have an international standard: C++0x is unanimously approved|website=Sutter's Mill}}</ref> [[C++11]] (14882:2011) included many additions to both the core language and the standard library.<ref name="isocpp2011"/><br />
<br />
In 2014, [[C++14]] (also known as C++1y) was released as a small extension to [[C++11]], featuring mainly bug fixes and small improvements.<ref name="The Future of C">{{cite web|title=The Future of C++|url=https://channel9.msdn.com/Events/Build/2012/2-005}}</ref> The Draft International Standard ballot procedures completed in mid-August 2014.<ref>{{cite web|title=We have C++14! : Standard C++|url=https://isocpp.org/blog/2014/08/we-have-cpp14}}</ref><br />
<br />
After C++14, a major revision [[C++17]], informally known as C++1z, was completed by the ISO C++ Committee in mid July 2017 and was approved and published in December 2017.<ref name="Toronto meeting report">[https://herbsutter.com/2017/07/15/trip-report-summer-iso-c-standards-meeting-toronto/ Trip report: Summer ISO C++ standards meeting (Toronto)]</ref><br />
<br />
As part of the standardization process, ISO also publishes [[International Organization for Standardization#International Standards and other publications|technical reports and specifications]]:<br />
* ISO/IEC TR 18015:2006<ref>{{cite web|publisher=International Organization for Standardization|title=ISO/IEC TR 18015:2006|url=https://www.iso.org/standard/43351.html}}</ref> on the use of C++ in embedded systems and on performance implications of C++ language and library features,<br />
* ISO/IEC TR 19768:2007<ref>{{cite web|url=https://www.iso.org/standard/43289.html|title=ISO/IEC TR 19768:2007|publisher=International Organization for Standardization}}</ref> (also known as the [[C++ Technical Report 1]]) on library extensions mostly integrated into [[C++11]],<br />
* ISO/IEC TR 29124:2010<ref>{{cite web|url=https://www.iso.org/standard/50511.html|title=ISO/IEC TR 29124:2010|publisher=International Organization for Standardization}}</ref> on special mathematical functions,<br />
* ISO/IEC TR 24733:2011<ref>{{cite web|url=https://www.iso.org/standard/38843.html|title=ISO/IEC TR 24733:2011|publisher=International Organization for Standardization}}</ref> on [[decimal floating point]] arithmetic,<br />
* ISO/IEC TS 18822:2015<ref>{{cite web|url=https://www.iso.org/standard/63483.html|title=ISO/IEC TS 18822:2015|publisher=International Organization for Standardization}}</ref> on the standard filesystem library,<br />
* ISO/IEC TS 19570:2015<ref>{{cite web|url=https://www.iso.org/standard/65241.html|title=ISO/IEC TS 19570:2015|publisher=International Organization for Standardization}}</ref> on [[Parallel computing|parallel]] versions of the standard library algorithms,<br />
* ISO/IEC TS 19841:2015<ref>{{cite web|url=https://www.iso.org/standard/66343.html|title=ISO/IEC TS 19841:2015|publisher=International Organization for Standardization}}</ref> on software [[transactional memory]],<br />
* ISO/IEC TS 19568:2015<ref>{{cite web|url=https://www.iso.org/standard/65238.html|title=ISO/IEC TS 19568:2015|publisher=International Organization for Standardization}}</ref> on a new set of library extensions, some of which are already integrated into [[C++17]],<br />
* ISO/IEC TS 19217:2015<ref>{{cite web|url=https://www.iso.org/standard/64031.html|title=ISO/IEC TS 19217:2015|publisher=International Organization for Standardization}}</ref> on the C++ [[concepts (C++)|concepts]], integrated into [[C++20]]<br />
* ISO/IEC TS 19571:2016<ref>{{cite web|url=https://www.iso.org/standard/65242.html|title=ISO/IEC TS 19571:2016|publisher=International Organization for Standardization}}</ref> on the library extensions for concurrency<br />
* ISO/IEC TS 19568:2017<ref>{{cite web|url=https://www.iso.org/standard/70587.html|title=ISO/IEC TS 19568:2017|publisher=International Organization for Standardization}}</ref> on a new set of general-purpose library extensions<br />
* ISO/IEC TS 21425:2017<ref>{{cite web|url=https://www.iso.org/standard/70910.html|title=ISO/IEC TS 21425:2017|publisher=International Organization for Standardization}}</ref> on the library extensions for ranges, integrated into [[C++20]]<br />
* ISO/IEC TS 22277:2017<ref>{{cite web|url=https://www.iso.org/standard/73008.html|title=ISO/IEC TS 22277:2017|publisher=International Organization for Standardization}}</ref> on coroutines<br />
* ISO/IEC TS 19216:2018<ref>{{cite web|url=https://www.iso.org/standard/64030.html|title=ISO/IEC TS 19216:2018|publisher=International Organization for Standardization}}</ref> on the networking library<br />
* ISO/IEC TS 21544:2018<ref>{{cite web|url=https://www.iso.org/standard/71051.html|title=ISO/IEC TS 21544:2018|publisher=International Organization for Standardization}}</ref> on modules<br />
* ISO/IEC TS 19570:2018<ref>{{cite web|url=https://www.iso.org/standard/70588.html|title=ISO/IEC TS 19570:2018|publisher=International Organization for Standardization}}</ref> on a new set of library extensions for parallelism<br />
More technical specifications are in development and pending approval, including static reflection.<ref>See a list at https://en.cppreference.com/w/cpp/experimental visited 15 February 2019.</ref><br />
<br />
== Language ==<br />
[[Image:Соколова.jpg|thumb|right|A programmer writing a C++ main() function in 2018]]<br />
The C++ language has two main components: a direct mapping of hardware features provided primarily by the C subset, and zero-overhead abstractions based on those mappings. Stroustrup describes C++ as "a light-weight abstraction programming language [designed] for building and using efficient and elegant abstractions";<ref name="Stroustrup1" /> and "offering both hardware access and abstraction is the basis of C++. Doing it efficiently is what distinguishes it from other languages."<ref>{{cite web|url=https://www.infoq.com/news/2015/04/stroustrup-cpp17-interview|author=B. Stroustrup (interviewed by Sergio De Simone)|date=30 April 2015|accessdate=8 July 2015|title=Stroustrup: Thoughts on C++17 - An Interview}}</ref><br />
<br />
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]]:<ref>{{Cite book |first=Bjarne |last=Stroustrup |year=2000 |page=46 |title=The C++ Programming Language |edition=Special |publisher=Addison-Wesley |isbn=0-201-70073-5 }}</ref><ref>{{cite web |url=http://www.stroustrup.com/3rd_issues.html |title=Open issues for The C++ Programming Language (3rd Edition) |first=Bjarne |last=Stroustrup |postscript=. 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.}}</ref><br />
<br />
<!--<br />
<br />
***************************************************************<br />
*<br />
* PLEASE NOTE:<br />
*<br />
* BEFORE MAKING CHANGES to the "Hello World" example<br />
* please establish consensus by discussing your proposed changes<br />
* on the Talk page. This is not the place to "Be Bold"; this<br />
* has been discussed before at length.<br />
*<br />
* If you change the sample program without discussion, it will be<br />
* reverted within a few minutes.<br />
*<br />
* Yes, you could say "using namespace std;" or "using std::cout;".<br />
* Yes, you could use "std::endl" rather than "\n".<br />
* Yes, you could add "return 0;" at the end.<br />
* Yes, you could add "int argc, char ** argv" to main.<br />
* Yes, your ancient compiler might require "#include <iostream.h>".<br />
* Yes, you could use "printf" from the Standard C Library.<br />
*<br />
* But don't<br />
*<br />
* The latest consensus is ''not'' to make any of those changes.<br />
* This is the example "Hello, world!" by Bjarne Stroustrup,<br />
* the author of the C++ language, and is used in<br />
* his book, "The C++ Programming Language (3rd edition)".<br />
*<br />
***************************************************************<br />
<br />
--><source lang="cpp" line="1"><br />
#include <iostream><br />
<br />
int main()<br />
{<br />
std::cout << "Hello, world!\n";<br />
}<br />
</source><!--<br />
<br />
*** PLEASE NOTE:****<br />
* BEFORE MAKING CHANGES to the "Hello World" example<br />
* please establish consensus by discussing your proposed changes<br />
* on the Talk page. This is not the place to "Be Bold"; this<br />
* has been discussed before.<br />
*<br />
* If you change the sample program without discussion, it will be<br />
* reverted within a few minutes.<br />
*<br />
* Yes, you could say "using namespace std;" or "using std::cout;".<br />
* Yes, you could use "std::endl" rather than "\n".<br />
* Yes, you could add "return 0;" at the end.<br />
* Yes, you could add "int argc, char ** argv" to main.<br />
* Yes, your ancient compiler might require "#include <iostream.h>".<br />
* Yes, you could use "printf" from the Standard C Library.<br />
*<br />
* But don't.<br />
*<br />
* The latest consensus is ''not'' to make any of those changes.<br />
* This is the example "Hello, world!" by Bjarne Stroustrup,<br />
* the author of the C++ language, and is used in<br />
* his book, "The C++ Programming Language (3rd edition)".<br />
*<br />
*************************************************************** --><br />
<br />
=== Object storage ===<br />
As in C, C++ supports four types of [[memory management]]: static storage duration objects, thread storage duration objects, automatic storage duration objects, and dynamic storage duration objects.<ref name="C++11 3.7">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7 Storage duration [basic.stc]''</ref><br />
<br />
==== Static storage duration objects ====<br />
Static storage duration objects are created before <code>main()</code> is entered (see exceptions below) and destroyed in reverse order of creation after <code>main()</code> exits. The exact order of creation is not specified by the standard (though there are some rules defined below) to allow implementations some freedom in how to organize their implementation. More formally, objects of this type have a lifespan that "shall last for the duration of the program".<ref name="C++11 3.7.1">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.1 Static Storage duration [basic.stc.static]''</ref><br />
<br />
Static storage duration objects are initialized in two phases. First, "static initialization" is performed, and only ''after'' all static initialization is performed, "dynamic initialization" is performed. In static initialization, all objects are first initialized with zeros; after that, all objects that have a constant initialization phase are initialized with the constant expression (i.e. variables initialized with a literal or <code>constexpr</code>). Though it is not specified in the standard, the static initialization phase can be completed at compile time and saved in the data partition of the executable. Dynamic initialization involves all object initialization done via a constructor or function call (unless the function is marked with <code>constexpr</code>, in C++11). The dynamic initialization order is defined as the order of declaration within the compilation unit (i.e. the same file). No guarantees are provided about the order of initialization between compilation units.<br />
<br />
==== Thread storage duration objects ====<br />
Variables of this type are very similar to static storage duration objects. The main difference is the creation time is just prior to thread creation and destruction is done after the thread has been joined.<ref name="C++11 3.7.2">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.2 Thread Storage duration [basic.stc.thread]''</ref><br />
<br />
==== Automatic storage duration objects ====<br />
The most common variable types in C++ are local variables inside a function or block, and temporary variables.<ref name="C++11 3.7.3">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.3 Automatic Storage duration [basic.stc.auto]''</ref> The common feature about automatic variables is that they have a lifetime that is limited to the scope of the variable. They are created and potentially initialized at the point of declaration (see below for details) and destroyed in the ''reverse'' order of creation when the scope is left. This is implemented by allocation on the [[Stack-based memory allocation|stack]].<br />
<br />
Local variables are created as the point of execution passes the declaration point. If the variable has a constructor or initializer this is used to define the initial state of the object. Local variables are destroyed when the local block or function that they are declared in is closed. C++ destructors for local variables are called at the end of the object lifetime, allowing a discipline for automatic resource management termed [[Resource Acquisition Is Initialization|RAII]], which is widely used in C++.<br />
<br />
Member variables are created when the parent object is created. Array members are initialized from 0 to the last member of the array in order. Member variables are destroyed when the parent object is destroyed in the reverse order of creation. i.e. If the parent is an "automatic object" then it will be destroyed when it goes out of scope which triggers the destruction of all its members.<br />
<br />
Temporary variables are created as the result of expression evaluation and are destroyed when the statement containing the expression has been fully evaluated (usually at the <code>;</code> at the end of a statement).<br />
<br />
==== Dynamic storage duration objects ====<br />
{{Main|new and delete (C++)}}<br />
<br />
These objects have a dynamic lifespan and can be created directly with a call to {{cpp|new}} and destroyed explicitly with a call to {{cpp|delete}}.<ref name="C++11 3.7.4">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.4 Dynamic Storage duration <nowiki>[</nowiki>basic.stc.dynamic<nowiki>]</nowiki>''</ref> C++ also supports <code>malloc</code> and <code>free</code>, from C, but these are not compatible with {{cpp|new}} and {{cpp|delete}}. Use of {{cpp|new}} returns an address to the allocated memory. The C++ Core Guidelines advise against using {{cpp|new}} directly for creating dynamic objects in favor of smart pointers through {{cpp|make_unique<T>}} for single ownership and {{cpp|make_shared<T>}} for reference-counted multiple ownership,<ref>{{Cite web|url=https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r11-avoid-calling-new-and-delete-explicitly|title=C++ Core Guidelines|website=isocpp.github.io|access-date=2020-02-09}}</ref> which were introduced in C++11.<br />
<br />
=== Templates ===<br />
{{See also|Template metaprogramming|Generic programming}}<br />
<br />
[[C++ templates]] enable [[generic programming]]. C++ supports function, class, alias, and variable templates. Templates may be parameterized by types, compile-time constants, and other templates. Templates are implemented by ''instantiation'' at compile-time. To instantiate a template, compilers substitute specific arguments for a template's parameters to generate a concrete function or class instance. Some substitutions are not possible; these are eliminated by an overload resolution policy described by the phrase "[[Substitution failure is not an error]]" (SFINAE). Templates are a powerful tool that can be used for [[generic programming]], [[template metaprogramming]], and code optimization, but this power implies a cost. Template use may increase code size, because each template instantiation produces a copy of the template code: one for each set of template arguments, however, this is the same or smaller amount of code that would be generated if the code was written by hand.<ref name=":0" /> This is in contrast to run-time generics seen in other languages (e.g., [[Generics in Java|Java]]) where at compile-time the type is erased and a single template body is preserved.<br />
<br />
Templates are different from [[Macro (computer science)|macro]]s: while both of these compile-time language features enable conditional compilation, templates are not restricted to lexical substitution. Templates are aware of the semantics and type system of their companion language, as well as all compile-time type definitions, and can perform high-level operations including programmatic flow control based on evaluation of strictly type-checked parameters. Macros are capable of conditional control over compilation based on predetermined criteria, but cannot instantiate new types, recurse, or perform type evaluation and in effect are limited to pre-compilation text-substitution and text-inclusion/exclusion. In other words, macros can control compilation flow based on pre-defined symbols but cannot, unlike templates, independently instantiate new symbols. Templates are a tool for static [[Polymorphism in object-oriented programming|polymorphism]] (see below) and [[generic programming]].<br />
<br />
In addition, templates are a compile time mechanism in C++ that is [[Turing-complete]], meaning that any computation expressible by a computer program can be computed, in some form, by a [[template metaprogramming|template metaprogram]] prior to runtime.<br />
<br />
In summary, a template is a compile-time parameterized function or class written without knowledge of the specific arguments used to instantiate it. After instantiation, the resulting code is equivalent to code written specifically for the passed arguments. In this manner, templates provide a way to decouple generic, broadly applicable aspects of functions and classes (encoded in templates) from specific aspects (encoded in template parameters) without sacrificing performance due to abstraction.<br />
<br />
=== Objects ===<br />
{{Main|C++ classes}}<br />
<br />
C++ introduces [[object-oriented programming]] (OOP) features to C. It offers [[class (computer science)|class]]es, which provide the four features commonly present in OOP (and some non-OOP) languages: [[Abstraction (computer science)|abstraction]], [[Information hiding|encapsulation]], [[Inheritance (object-oriented programming)|inheritance]], and [[Polymorphism (computer science)|polymorphism]]. One distinguishing feature of C++ classes compared to classes in other programming languages is support for deterministic [[destructor (computer science)|destructors]], which in turn provide support for the [[Resource Acquisition is Initialization]] (RAII) concept.<br />
<br />
==== Encapsulation ====<br />
[[Information hiding|Encapsulation]] is the hiding of information to ensure that data structures and operators are used as intended and to make the usage model more obvious to the developer. C++ provides the ability to define classes and functions as its primary encapsulation mechanisms. Within a class, members can be declared as either public, protected, or private to explicitly enforce encapsulation. A public member of the class is accessible to any function. A private member is accessible only to functions that are members of that class and to functions and classes explicitly granted access permission by the class ("friends"). A protected member is accessible to members of classes that inherit from the class in addition to the class itself and any friends.<br />
<br />
The object-oriented principle ensures the encapsulation of all and only the functions that access the internal representation of a type. C++ supports this principle via member functions and friend functions, but it does not enforce it. Programmers can declare parts or all of the representation of a type to be public, and they are allowed to make public entities not part of the representation of a type. Therefore, C++ supports not just object-oriented programming, but other decomposition paradigms such as [[Modularity (programming)|modular programming]].<br />
<br />
It is generally considered good practice to make all [[data]] private or protected, and to make public only those functions that are part of a minimal interface for users of the class. This can hide the details of data implementation, allowing the designer to later fundamentally change the implementation without changing the interface in any way.<ref name="cppcs">{{Cite book |first1=Herb |last1=Sutter |first2=Andrei |last2=Alexandrescu |authorlink1=Herb Sutter |authorlink2=Andrei Alexandrescu |year=2004 |title=C++ Coding Standards: 101 Rules, Guidelines, and Best Practices |publisher = Addison-Wesley }}</ref><ref name="industrialcpp">{{Cite book |last1=Henricson |first1=Mats |last2=Nyquist |first2=Erik |title=Industrial Strength C++ |publisher=Prentice Hall |year=1997 |isbn=0-13-120965-5 |url=https://archive.org/details/industrialstreng0000henr }}</ref><br />
<br />
==== Inheritance ====<br />
[[Inheritance (computer science)|Inheritance]] allows one data type to acquire properties of other data types. Inheritance from a [[base class]] may be declared as public, protected, or private. This access specifier determines whether unrelated and derived classes can access the inherited public and protected members of the base class. Only public inheritance corresponds to what is usually meant by "inheritance". The other two forms are much less frequently used. If the access specifier is omitted, a "class" inherits privately, while a "struct" inherits publicly. Base classes may be declared as virtual; this is called [[virtual inheritance]]. Virtual inheritance ensures that only one instance of a base class exists in the inheritance graph, avoiding some of the ambiguity problems of multiple inheritance.<br />
<br />
[[Multiple inheritance]] is a C++ feature not found in most other languages, allowing a class to be derived from more than one base class; this allows for more elaborate inheritance relationships. For example, a "Flying Cat" class can inherit from both "Cat" and "Flying Mammal". Some other languages, such as [[C Sharp (programming language)|C#]] or [[Java (programming language)|Java]], accomplish something similar (although more limited) by allowing inheritance of multiple [[Interface (computer science)|interfaces]] while restricting the number of base classes to one (interfaces, unlike classes, provide only declarations of member functions, no implementation or member data). An interface as in C# and Java can be defined in C++ as a class containing only pure virtual functions, often known as an [[abstract base class]] or "ABC". The member functions of such an abstract base class are normally explicitly defined in the derived class, not inherited implicitly. C++ virtual inheritance exhibits an ambiguity resolution feature called [[Dominance (C++)|dominance]].<br />
<br />
=== Operators and operator overloading ===<br />
{| class="wikitable" style="float: right; margin: 0.5em 0 1em 2em;"<br />
|+ Operators that cannot be overloaded<br />
! style="text-align: center" | Operator<br />
! style="width: 9em" | Symbol<br />
|-<br />
! style="text-align: center" | Scope resolution operator<br />
| {{C-lang| ::}}<br />
|-<br />
! style="text-align: center" | Conditional operator<br />
| {{C-lang| ?:}}<br />
|-<br />
! style="text-align: center" | dot operator<br />
| {{C-lang| .}}<br />
|-<br />
<br />
|-<br />
! style="text-align: center" | Member selection operator<br />
| {{C-lang| .*}}<br />
|-<br />
! style="text-align: center" | "sizeof" operator<br />
| {{C-lang| sizeof}}<br />
|-<br />
! style="text-align: center" | "typeid" operator<br />
| {{C-lang| typeid}}<br />
|}<br />
{{Main|Operators in C and C++}}<br />
C++ provides more than 35 operators, covering basic arithmetic, bit manipulation, indirection, comparisons, logical operations and others. Almost all operators can be [[Operator overloading|overloaded]] for user-defined types, with a few notable exceptions such as member access (<code>.</code> and <code>.*</code>) as well as the conditional operator. The rich set of overloadable operators is central to making user-defined types in C++ seem like built-in types.<br />
<br />
Overloadable operators are also an essential part of many advanced C++ programming techniques, such as [[smart pointer]]s. Overloading an operator does not change the precedence of calculations involving the operator, nor does it change the number of operands that the operator uses (any operand may however be ignored by the operator, though it will be evaluated prior to execution). Overloaded "<code>&&</code>" and "<code>||</code>" operators lose their [[short-circuit evaluation]] property.<br />
<br />
=== Polymorphism ===<br />
{{See also|Polymorphism (computer science)}}<br />
<br />
[[Type polymorphism|Polymorphism]] enables one common interface for many implementations, and for objects to act differently under different circumstances.<br />
<br />
C++ supports several kinds of ''static'' (resolved at [[compile-time]]) and ''dynamic'' (resolved at [[Run time (program lifecycle phase)|run-time]]) [[polymorphism (computer science)|polymorphism]]s, supported by the language features described above. [[Compile-time polymorphism]] does not allow for certain run-time decisions, while [[runtime polymorphism]] typically incurs a performance penalty.<br />
<br />
==== Static polymorphism ====<br />
{{See also|Parametric polymorphism|ad hoc polymorphism}}<br />
<br />
[[Function overloading]] allows programs to declare multiple functions having the same name but with different arguments (i.e. [[ad hoc polymorphism|''ad hoc'' polymorphism]]). The functions are distinguished by the number or types of their [[Parameter (computer science)|formal parameter]]s. Thus, the same function name can refer to different functions depending on the context in which it is used. The type returned by the function is not used to distinguish overloaded functions and would result in a compile-time error message.<br />
<br />
When declaring a function, a programmer can specify for one or more parameters a [[default arguments|default value]]. Doing so allows the parameters with defaults to optionally be omitted when the function is called, in which case the default arguments will be used. When a function is called with fewer arguments than there are declared parameters, explicit arguments are matched to parameters in left-to-right order, with any unmatched parameters at the end of the parameter list being assigned their default arguments. In many cases, specifying default arguments in a single function declaration is preferable to providing overloaded function definitions with different numbers of parameters.<br />
<br />
[[Generic programming#Templates|Templates]] in C++ provide a sophisticated mechanism for writing generic, polymorphic code (i.e. [[parametric polymorphism]]). In particular, through the [[curiously recurring template pattern]], it's possible to implement a form of static polymorphism that closely mimics the syntax for overriding virtual functions. Because C++ templates are type-aware and [[Turing-complete]], they can also be used to let the compiler resolve recursive conditionals and generate substantial programs through [[template metaprogramming]]. Contrary to some opinion, template code will not generate a bulk code after compilation with the proper compiler settings.<ref name=":0">{{cite web |accessdate=8 March 2010 |publisher=EmptyCrate Software. Travel. Stuff. |location=articles.emptycrate.com/ |title=Nobody Understands C++: Part 5: Template Code Bloat |date=6 May 2008 |url=https://articles.emptycrate.com/2008/05/06/nobody_understands_c_part_5_template_code_bloat.html |quote=On occasion you will read or hear someone talking about C++ templates causing code bloat. I was thinking about it the other day and thought to myself, "self, if the code does exactly the same thing then the compiled code cannot really be any bigger, can it?" [...] And what about compiled code size? Each were compiled with the command g++ <filename>.cpp -O3. Non-template version: 8140 bytes, template version: 8028 bytes! }}</ref><br />
<br />
==== Dynamic polymorphism ====<br />
<br />
===== Inheritance =====<br />
{{See also|Subtyping}}<br />
<br />
Variable pointers and references to a base class type in C++ can also refer to objects of any derived classes of that type. This allows arrays and other kinds of containers to hold pointers to objects of differing types (references cannot be directly held in containers). This enables dynamic (run-time) polymorphism, where the referred objects can behave differently, depending on their (actual, derived) types.<br />
<br />
C++ also provides the <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> operator, which allows code to safely attempt conversion of an object, via a base reference/pointer, to a more derived type: ''downcasting''. The ''attempt'' is necessary as often one does not know which derived type is referenced. (''Upcasting'', conversion to a more general type, can always be checked/performed at compile-time via <syntaxhighlight lang="C++" inline>static_cast</syntaxhighlight>, as ancestral classes are specified in the derived class's interface, visible to all callers.) <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> relies on [[run-time type information]] (RTTI), metadata in the program that enables differentiating types and their relationships. If a <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> to a pointer fails, the result is the <syntaxhighlight lang="C++" inline>nullptr</syntaxhighlight> constant, whereas if the destination is a reference (which cannot be null), the cast throws an exception. Objects ''known'' to be of a certain derived type can be cast to that with <syntaxhighlight lang="C++" inline>static_cast</syntaxhighlight>, bypassing RTTI and the safe runtime type-checking of <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight>, so this should be used only if the programmer is very confident the cast is, and will always be, valid.<br />
<br />
===== Virtual member functions =====<br />
Ordinarily, when a function in a derived class [[Method overriding (programming)|overrides]] a function in a base class, the function to call is determined by the type of the object. A given function is overridden when there exists no difference in the number or type of parameters between two or more definitions of that function. Hence, at compile time, it may not be possible to determine the type of the object and therefore the correct function to call, given only a base class pointer; the decision is therefore put off until runtime. This is called [[dynamic dispatch]]. [[virtual functions|Virtual member functions]] or ''methods''<ref>{{Cite book |quote=A virtual member function is sometimes called a ''method''. |first=Bjarne |last=Stroustrup |year=2000 |page=310 |title=The C++ Programming Language |edition=Special |publisher=Addison-Wesley |isbn = 0-201-70073-5 }}</ref> allow the most specific implementation of the function to be called, according to the actual run-time type of the object. In C++ implementations, this is commonly done using [[virtual function table]]s. If the object type is known, this may be bypassed by prepending a [[fully qualified name|fully qualified class name]] before the function call, but in general calls to virtual functions are resolved at run time.<br />
<br />
In addition to standard member functions, operator overloads and destructors can be virtual. As a rule of thumb, if any function in the class is virtual, the destructor should be as well. As the type of an object at its creation is known at compile time, constructors, and by extension copy constructors, cannot be virtual. Nonetheless a situation may arise where a copy of an object needs to be created when a pointer to a derived object is passed as a pointer to a base object. In such a case, a common solution is to create a <syntaxhighlight lang="C++" inline>clone()</syntaxhighlight> (or similar) virtual function that creates and returns a copy of the derived class when called.<br />
<br />
A member function can also be made "pure virtual" by appending it with <syntaxhighlight lang="C++" inline>= 0</syntaxhighlight> after the closing parenthesis and before the semicolon. A class containing a pure virtual function is called an ''abstract class''. Objects cannot be created from an abstract class; they can only be derived from. Any derived class inherits the virtual function as pure and must provide a non-pure definition of it (and all other pure virtual functions) before objects of the derived class can be created. A program that attempts to create an object of a class with a pure virtual member function or inherited pure virtual member function is ill-formed.<br />
<br />
=== Lambda expressions ===<br />
C++ provides support for [[anonymous function]]s, also known as lambda expressions, with the following form:<br />
<br />
<source lang="cpp"><br />
[capture](parameters) -> return_type { function_body }<br />
</source><br />
<br />
The return type of a lambda expression can also be automatically inferred, if possible, e.g.:<br />
<br />
<source lang="cpp"><br />
[](int x, int y) { return x - y; } // inferred<br />
[](int x, int y) -> int { return x + y; } // explicit<br />
</source><br />
<br />
The <syntaxhighlight lang="C++" inline>[capture]</syntaxhighlight> list supports the definition of [[Closure (computer programming)|closures]]. Such lambda expressions are defined in the standard as [[syntactic sugar]] for an unnamed [[function object]].<br />
<br />
=== Exception handling ===<br />
Exception handling is used to communicate the existence of a runtime problem or error from where it was detected to where the issue can be handled.<ref>{{Cite web|url = http://www.cl.cam.ac.uk/teaching/1314/CandC++/lecture7.pdf|title = <nowiki>C and C++ Exceptions | Templates</nowiki>|date = 2013|accessdate = 30 August 2016|website = Cambridge Computer Laboratory - Course Materials 2013-14|publisher = |last = Mycroft|first = Alan}}</ref> It permits this to be done in a uniform manner and separately from the main code, while detecting all errors.<ref name="exception_summary">{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 345}}</ref> Should an error occur, an exception is thrown (raised), which is then caught by the nearest suitable exception handler. The exception causes the current scope to be exited, and also each outer scope (propagation) until a suitable handler is found, calling in turn the destructors of any objects in these exited scopes.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 363–365}}</ref> At the same time, an exception is presented as an object carrying the data about the detected problem.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 345, 363}}</ref><br />
<br />
Some C++ style guides, such as Google's,<ref>{{cite web |title=Google C++ Style Guide |url=https://google.github.io/styleguide/cppguide.html#Exceptions |accessdate=25 June 2019}}</ref> LLVM's,<ref>{{cite web |title=LLVM Coding Standards |url=https://llvm.org/docs/CodingStandards.html#do-not-use-rtti-or-exceptions |website=LLVM 9 documentation |accessdate=25 June 2019}}</ref> and Qt's<ref>{{cite web |title=Coding Conventions |url=https://wiki.qt.io/Coding_Conventions |website=Qt Wiki |accessdate=26 June 2019}}</ref> forbid the usage of exceptions.<br />
<br />
The exception-causing code is placed inside a <syntaxhighlight lang="C++" inline>try</syntaxhighlight> block. The exceptions are handled in separate <syntaxhighlight lang="C++" inline>catch</syntaxhighlight> blocks (the handlers); each <syntaxhighlight lang="C++" inline>try</syntaxhighlight> block can have multiple exception handlers, as it is visible in the example below.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 344, 370}}</ref><br />
<!--"#include <iostream.h> is deprecated"--><br />
<source lang="cpp" line="1"><br />
#include <iostream><br />
#include <vector><br />
#include <stdexcept><br />
<br />
int main() {<br />
try {<br />
std::vector<int> vec{3, 4, 3, 1};<br />
int i{vec.at(4)}; // Throws an exception, std::out_of_range (indexing for vec is from 0-3 not 1-4)<br />
}<br />
// An exception handler, catches std::out_of_range, which is thrown by vec.at(4)<br />
catch (std::out_of_range &e) {<br />
std::cerr << "Accessing a non-existent element: " << e.what() << '\n';<br />
}<br />
// To catch any other standard library exceptions (they derive from std::exception)<br />
catch (std::exception &e) {<br />
std::cerr << "Exception thrown: " << e.what() << '\n';<br />
}<br />
// Catch any unrecognised exceptions (i.e. those which don't derive from std::exception)<br />
catch (...) {<br />
std::cerr << "Some fatal error\n";<br />
}<br />
}<br />
</source><br />
<br />
It is also possible to raise exceptions purposefully, using the <syntaxhighlight lang="C++" inline>throw</syntaxhighlight> keyword; these exceptions are handled in the usual way. In some cases, exceptions cannot be used due to technical reasons. One such example is a critical component of an embedded system, where every operation must be guaranteed to complete within a specified amount of time. This cannot be determined with exceptions as no tools exist to determine the maximum time required for an exception to be handled.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 349}}</ref><br />
<br />
Unlike [[Signal handler|signal handling]], in which the handling function is called from the point of failure, exception handling exits the current scope before the catch block is entered, which may be located in the current function or any of the previous function calls currently on the stack.<br />
<br />
== Standard library ==<br />
[[Image:ANSI ISO C++ WP.jpg|thumb|right|The draft "Working Paper" standard that became approved as C++98; half of its size was devoted to the C++ Standard Library]]<br />
{{Main|C++ Standard Library}}<br />
The C++ [[standardization|standard]] consists of two parts: the core language and the standard library. C++ programmers expect the latter on every major implementation of C++; it includes aggregate types ([[sequence container (C++)#Vector|vectors]], lists, maps, sets, queues, stacks, arrays, tuples), [[algorithm]]s (find, [[Foreach loop|for_each]], [[Binary search algorithm|binary_search]], random_shuffle, etc.), input/output facilities ([[iostream]], for reading from and writing to the console and files), filesystem library, localisation support, [[smart pointers]] for automatic memory management, [[regular expression]] support, [[multithreading (software)|multi-threading]] library, atomics support (allowing a variable to be read or written to by at most one thread at a time without any external synchronisation), time utilities (measurement, getting current time, etc.), a system for converting error reporting that doesn't use C++ [[exception handling|exceptions]] into C++ exceptions, a [[random number generator]] and a slightly modified version of the [[C standard library]] (to make it comply with the C++ type system).<br />
<br />
A large part of the C++ library is based on the [[Standard Template Library]] (STL). Useful tools provided by the STL include [[container (data structure)|container]]s as the collections of objects (such as [[array data structure|vector]]s and [[linked list|lists]]), [[iterator]]s that provide array-like access to containers, and [[algorithm]]s that perform operations such as searching and sorting.<br />
<br />
Furthermore, (multi)maps ([[associative array]]s) and (multi)sets are provided, all of which export compatible interfaces. Therefore, using templates it is possible to write generic algorithms that work with any container or on any sequence defined by iterators. As in C, the [[feature (software design)|feature]]s of the [[library (computing)|library]] are accessed by using the <syntaxhighlight lang="C++" inline>#include</syntaxhighlight> [[directive (programming)|directive]] to include a [[standard header]]. The [[C++ Standard Library]] provides 105 standard headers, of which 27 are deprecated.<br />
<br />
The standard incorporates the STL that was originally designed by [[Alexander Stepanov]], who experimented with generic algorithms and containers for many years. When he started with C++, he finally found a language where it was possible to create generic algorithms (e.g., STL sort) that perform even better than, for example, the C standard library qsort, thanks to C++ features like using inlining and compile-time binding instead of function pointers. The standard does not refer to it as "STL", as it is merely a part of the standard library, but the term is still widely used to distinguish it from the rest of the standard library (input/output streams, internationalization, diagnostics, the C library subset, etc.).<ref>{{cite web|url=http://www.stlport.org/resources/StepanovUSA.html |author=Graziano Lo Russo |title=An Interview with A. Stepanov |year=2008 |accessdate=8 October 2015 |website=stlport.org}}</ref><br />
<br />
Most C++ compilers, and all major ones, provide a standards-conforming implementation of the C++ standard library.<br />
<br />
== Compatibility ==<br />
To give compiler vendors greater freedom, the C++ standards committee decided not to dictate the implementation of [[name mangling]], [[exception handling]], and other implementation-specific features. The downside of this decision is that [[object code]] produced by different [[compiler]]s is expected to be incompatible. There were, however, attempts to standardize compilers for particular machines or [[operating system]]s (for example C++ ABI),<ref>{{cite web |url=https://mentorembedded.github.io/cxx-abi/ |title=C++ ABI Summary |date=20 March 2001 |accessdate=30 May 2006 }}</ref> though they seem to be largely abandoned now.<br />
<br />
=== With C ===<br />
[[Image:C slash cpp.svg|thumb|right|upright=0.6|The relationship of C++ to C has always been a bit problematic]]<br />
{{Details|Compatibility of C and C++}}<br />
<br />
C++ is often considered to be a superset of [[C (programming language)|C]] but this is not strictly true.<ref name="superset">{{cite web |url=http://www.stroustrup.com/bs_faq.html#C-is-subset |title=Bjarne Stroustrup's FAQ&nbsp;– Is C a subset of C++? |accessdate=5 May 2014}}</ref> Most C code can easily be made to compile correctly in C++ but there are a few differences that cause some valid C code to be invalid or behave differently in C++. For example, C allows implicit conversion from <syntaxhighlight lang="C++" inline>void*</syntaxhighlight> to other pointer types but C++ does not (for type safety reasons). Also, C++ defines many new keywords, such as <syntaxhighlight lang="C++" inline>new</syntaxhighlight> and <syntaxhighlight lang="C++" inline>class</syntaxhighlight>, which may be used as identifiers (for example, variable names) in a C program.<br />
<br />
Some incompatibilities have been removed by the 1999 revision of the C standard ([[C99]]), which now supports C++ features such as line comments (<syntaxhighlight lang="C++" inline>//</syntaxhighlight>) and declarations mixed with code. On the other hand, C99 introduced a number of new features that C++ did not support that were incompatible or redundant in C++, such as [[variable-length array]]s, native complex-number types (however, the <syntaxhighlight lang="C++" inline>std::complex</syntaxhighlight> class in the C++ standard library provides similar functionality, although not code-compatible), designated initializers, [[C syntax#Compound literals|compound literals]], and the <syntaxhighlight lang="C++" inline>restrict</syntaxhighlight> keyword.<ref>{{cite web |url=http://home.datacomm.ch/t_wolf/tw/c/c9x_changes.html |title=C9X – The New C Standard |accessdate=27 December 2008 }}</ref> Some of the C99-introduced features were included in the subsequent version of the C++ standard, [[C++11#Improved C compatibility|C++11]] (out of those which were not redundant).<ref>{{cite web |title=C++0x Support in GCC |url=https://gcc.gnu.org/projects/cxx0x.html |accessdate=12 October 2010}}</ref><ref>{{cite web |title=C++0x Core Language Features In VC10: The Table |url=https://blogs.msdn.com/b/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx |accessdate=12 October 2010 }}</ref><ref>{{cite web|url=https://clang.llvm.org/cxx_status.html |title=Clang - C++98, C++11, and C++14 Status |publisher=Clang.llvm.org |date=12 May 2013 |accessdate=10 June 2013}}</ref> However, the C++11 standard introduces new incompatibilities, such as disallowing assignment of a string literal to a character pointer, which remains valid C.<br />
<br />
To intermix C and C++ code, any function declaration or definition that is to be called from/used both in C and C++ must be declared with C linkage by placing it within an <syntaxhighlight style=white-space:nowrap lang="C++" inline>extern "C" {/*...*/}</syntaxhighlight> block. Such a function may not rely on features depending on [[name mangling]] (i.e., function overloading).<br />
<br />
== Criticism ==<br />
{{Main|Criticism of C++}}<br />
<br />
Despite its widespread adoption, some notable programmers have criticized the C++ language, including [[Linus Torvalds]],<ref name=torvalds>{{cite mailing list |url=https://lwn.net/Articles/249460/ |title=Re: [RFC] Convert builin-mailinfo.c to use The Better String Library |date=6 September 2007 |accessdate=31 March 2015 }}</ref> [[Richard Stallman]],<ref>{{cite mailing list |url=http://harmful.cat-v.org/software/c++/rms |title=Re: Efforts to attract more users? |date=12 July 2010 |accessdate=31 March 2015 }}</ref> [[Joshua Bloch]], [[Ken Thompson]],<ref>{{cite web |url=https://www.drdobbs.com/open-source/interview-with-ken-thompson/229502480 |title=Dr. Dobb's: Interview with Ken Thompson |author=Andrew Binstock |date=18 May 2011 |accessdate=7 February 2014}}</ref><ref name="Seibel2009">{{cite book|author=Peter Seibel|title=Coders at Work: Reflections on the Craft of Programming|url=https://books.google.com/books?id=nneBa6-mWfgC&pg=PA475|date=16 September 2009|publisher=Apress|isbn=978-1-4302-1948-4|pages=475–476}}</ref><ref name="gigamonkeysWordpress">https://gigamonkeys.wordpress.com/2009/10/16/coders-c-plus-plus/</ref> and [[Donald Knuth]].<ref name="dobbsKnuth">https://www.drdobbs.com/architecture-and-design/an-interview-with-donald-knuth/228700500</ref><ref name="knuth1993">http://tex.loria.fr/litte/knuth-interview</ref><br />
<br />
One of the most often criticised points of C++ is its perceived complexity as a language, with the criticism that a large number of non-orthogonal features in practice necessitates restricting code to subset of C++, thus eschewing the readability benefits of common style and idioms. As expressed by [[Joshua Bloch]]: <blockquote> I think C++ was pushed well beyond its complexity threshold, and yet there are a lot of people programming it. But what you do is you force people to subset it. So almost every shop that I know of that uses C++ says, “Yes, we’re using C++ but we’re not doing multiple-implementation inheritance and we’re not using operator overloading.” There are just a bunch of features that you’re not going to use because the complexity of the resulting code is too high. And I don’t think it’s good when you have to start doing that. You lose this programmer portability where everyone can read everyone else’s code, which I think is such a good thing. </blockquote><br />
<br />
[[Donald Knuth]] (1993, commenting on pre-standardized C++), who said of [[Edsger Dijkstra]] that "to think of programming in C++" "would make him physically ill":<ref name="dobbsKnuth" /><ref name="knuth1993" /> <blockquote> The problem that I have with them today is that... C++ is too complicated. At the moment, it's impossible for me to write portable code that I believe would work on lots of different systems, unless I avoid all exotic features. Whenever the C++ language designers had two competing ideas as to how they should solve some problem, they said "OK, we'll do them both". So the language is too baroque for my taste. </blockquote><br />
<br />
[[Ken Thompson]], who was a colleague of Stroustrup at Bell Labs, gives his assessment:<ref name="Seibel2009" /><ref name="gigamonkeysWordpress" /> <blockquote> It certainly has its good points. But by and large I think it’s a bad language. It does a lot of things half well and it’s just a garbage heap of ideas that are mutually exclusive. Everybody I know, whether it’s personal or corporate, selects a subset and these subsets are different. So it’s not a good language to transport an algorithm—to say, “I wrote it; here, take it.” It’s way too big, way too complex. And it’s obviously [[Design by committee|built by a committee]]. <br />
Stroustrup campaigned for years and years and years, way beyond any sort of technical contributions he made to the language, to get it adopted and used. And he sort of ran all the standards committees with a whip and a chair. And he said “no” to no one. He put every feature in that language that ever existed. It wasn’t cleanly designed—it was just the union of everything that came along. And I think it suffered drastically from that. </blockquote><br />
<br />
However [[Brian Kernighan]], also a colleague at Bell Labs, disputes this assessment:<ref>{{cite video|people=Brian Kernighan|date=July 18, 2018|title=Brian Kernighan Q&A - Computerphile|url=https://www.youtube.com/watch?v=zmYhR8cUX90&t=5m17s}}</ref> <blockquote>C++ has been enormously influential. ... Lots of people say C++ is too big and too complicated etc. etc. but in fact it is a very powerful language and pretty much everything that is in there is there for a really sound reason: it is not somebody doing random invention, it is actually people trying to solve real world problems. Now a lot of the programs that we take for granted today, that we just use, are C++ programs. </blockquote><br />
<br />
Stroustrup himself comments that C++ semantics are much cleaner than its syntax: "within C++, there is a much smaller and cleaner language struggling to get out".<ref>http://www.stroustrup.com/bs_faq.html#really-say-that</ref><br />
<br />
Other complaints may include a lack of [[reflection (computer programming)|reflection]] or [[garbage collection (computer science)|garbage collection]], long compilation times, perceived [[feature creep]],<ref>{{cite web |url=https://commandcenter.blogspot.mx/2012/06/less-is-exponentially-more.html |title=Less is exponentially more |year=2012 |last=Pike |first=Rob}}</ref> and verbose error messages, particularly from template metaprogramming.<ref>{{cite web|url=https://yosefk.com/c++fqa/defective.html|title=Defective C++|first=Yossi|last=Kreinin|date=13 October 2009|accessdate=3 February 2016}}</ref><br />
<br />
== See also ==<br />
{{Portal|Computer programming}}<br />
* [[Comparison of programming languages]]<br />
* [[List of C++ compilers]]<br />
* [[Outline of C++]]<br />
* [[:Category:C++ libraries|C++ Libraries (category)]]<br />
<br />
== References ==<br />
{{Reflist|30em}}<br />
<br />
== Further reading ==<br />
{{Refbegin|30em}}<br />
* {{Cite book |first=David |last=Abrahams |authorlink=David Abrahams (computer programmer) |first2=Aleksey |last2=Gurtovoy |title=C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond |publisher=Addison-Wesley |isbn=0-321-22725-5 }}<br />
* {{Cite book |first=Andrei |last=Alexandrescu |authorlink=Andrei Alexandrescu |year=2001 |title=Modern C++ Design: Generic Programming and Design Patterns Applied |publisher=Addison-Wesley |isbn=0-201-70431-5 }}<br />
* {{Cite book |first=Andrei |last=Alexandrescu |authorlink=Andrei Alexandrescu |first2=Herb |last2=Sutter |authorlink2=Herb Sutter|year=2004 |title=C++ Design and Coding Standards: Rules and Guidelines for Writing Programs |publisher=Addison-Wesley |isbn=0-321-11358-6 }}<br />
* {{Cite book |first=Pete |last=Becker |authorlink=Pete Becker |year=2006 |title=The C++ Standard Library Extensions : A Tutorial and Reference |publisher=Addison-Wesley |isbn=0-321-41299-0 }}<br />
* {{Cite book |first=Frank |last=Brokken |year=2010 |title=C++ Annotations |publisher=University of Groningen |isbn=90-367-0470-7 |url=http://www.icce.rug.nl/documents/cplusplus/ }}<br />
* {{Cite book |first=James O. |last=Coplien |authorlink=James O. Coplien |origyear=reprinted with corrections, original year of publication 1992 |date=1994 |title=Advanced C++: Programming Styles and Idioms |isbn=0-201-54855-0 |url=https://archive.org/details/advancedcbsprogr00copl }}<br />
* {{Cite book |first=Stephen C. |last=Dewhurst |year=2005 |title=C++ Common Knowledge: Essential Intermediate Programming |publisher=Addison-Wesley |isbn=0-321-32192-8 }}<br />
* {{Cite book |author=Information Technology Industry Council |authorlink=Information and Communications Technology Council |publisher=ISO/IEC |location=Geneva |title=Programming languages&nbsp;– C++ |id=14882:2003(E) |edition=Second |date=15 October 2003 }}<br />
* {{Cite book |first=Nicolai M. |last=Josuttis |title=The C++ Standard Library, A Tutorial and Reference |edition=Second|year=2012 |publisher=Addison-Wesley |isbn=0-321-62321-5}}<br />
* {{Cite book |first=Andrew |last=Koenig |authorlink=Andrew Koenig (programmer) |first2=Barbara E. |last2=Moo |year=2000 |title=Accelerated C++ – Practical Programming by Example |publisher=Addison-Wesley |isbn=0-201-70353-X |url=https://archive.org/details/acceleratedcprac2000koen }}<br />
* {{Cite book |first=Stanley B. |last=Lippman |authorlink=Stanley B. Lippman |first2=Josée |last2=Lajoie |first3=Barbara E. |last3=Moo |year=2011|edition=Fifth |title=C++ Primer |url=https://archive.org/details/cprimer0000lipp_5thed |url-access=registration |publisher=Addison-Wesley |isbn= 0-321-71411-3}}<br />
* {{Cite book |first=Stanley B. |last=Lippman |year=1996 |title=Inside the C++ Object Model |publisher=Addison-Wesley |isbn=0-201-83454-5 }}<br />
* {{Cite book |first=Scott |last=Meyers |authorlink=Scott Meyers |year=2005 |title=Effective C++ |edition=Third |publisher=Addison-Wesley |isbn=0-321-33487-6 |url=https://archive.org/details/effectivec55spec00meye }}<br />
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup |year=2013 |title=The C++ Programming Language |edition=Fourth |publisher=Addison-Wesley |isbn=978-0-321-56384-2 }}<br />
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup |year=1994 |title=The Design and Evolution of C++ |publisher=Addison-Wesley |isbn=0-201-54330-3 }}<br />
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup|year=2014 |title=Programming Principles and Practice Using C++ |edition=Second |publisher=Addison-Wesley |isbn=978-0-321-99278-9 }}<br />
* {{Cite book |first=Herb |last=Sutter|authorlink=Herb Sutter |year=2001 |title=More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions |publisher=Addison-Wesley |isbn=0-201-70434-X }}<br />
* {{Cite book |first=Herb |last=Sutter|authorlink=Herb Sutter |year=2004 |title=Exceptional C++ Style |publisher=Addison-Wesley |isbn=0-201-76042-8 }}<br />
* {{Cite book |first=David |last=Vandevoorde |first2=Nicolai M. |last2=Josuttis |year=2003 |title=C++ Templates: The complete Guide |publisher=Addison-Wesley |isbn=0-201-73484-2 }}<br />
{{refend}}<br />
<br />
== External links ==<br />
{{Sister project links|n=no|s=no|b=Subject:C++ programming language}}<br />
* [http://www.open-std.org/jtc1/sc22/wg21/ JTC1/SC22/WG21]{{snd}} the ISO/IEC C++ Standard Working Group<br />
* [https://isocpp.org/ Standard C++ Foundation]{{snd}} a non-profit organization that promotes the use and understanding of standard C++. Bjarne Stroustrup is a director of the organization.<br />
<br />
{{ISO standards}}<br />
{{Programming languages}}<br />
{{C++ programming language}}<br />
{{List of International Electrotechnical Commission standards}}<br />
{{Authority control}}<br />
<br />
{{DEFAULTSORT:C}}<br />
[[Category:Algol programming language family]]<br />
[[Category:C++| ]]<br />
[[Category:C++ programming language family]]<br />
[[Category:Class-based programming languages]]<br />
[[Category:Cross-platform software]]<br />
[[Category:High-level programming languages]]<br />
[[Category:Object-oriented programming languages]]<br />
[[Category:Programming languages created in 1983]]<br />
[[Category:Programming languages with an ISO standard]]<br />
[[Category:Statically typed programming languages]]</div>C++ Trolling Algorithmhttps://en.wikipedia.org/w/index.php?title=C%2B%2B&diff=943900408C++2020-03-04T14:17:41Z<p>C++ Trolling Algorithm: </p>
<hr />
<div>{{Redirect|CXX|the Roman numerals|120 (number)}}<br />
{{pp-move-vandalism|small=yes}}<br />
{{short description|General-purpose programming language}}<br />
{{Use dmy dates|date=January 2020 }}<br />
<br />
{{Infobox programming language<br />
| name = C++<br />
| logo = File:ISO C++ Logo.svg<br />
| logo caption = The C++ logo endorsed by Standard C++<br />
| logo size = 150px<br />
| paradigms = [[Multi-paradigm programming language|Multi-paradigm]]: [[procedural programming|procedural]], [[functional programming|functional]], [[object-oriented programming|object-oriented]], [[generic programming|generic]]<br />
| family = [[C (programming language)|C]]<br />
| designer = [[Bjarne Stroustrup]]<br />
| developer = ISO/IEC JTC1 (Joint Technical Committee 1) / SC22 (Subcommittee 22) / WG21 (Working Group 21)<br />
| released = {{Start date and age|df=yes|1985}}<br />
| latest release version = C++17 {{Small|(ISO/IEC 14882:2017)}}<br />
| latest release date = {{Start date and age|2017|12|01|df=yes}}<br />
| latest preview version = C++20<br />
| latest preview date = <br />
| typing = [[Static type|Static]], [[Nominal type system|nominative]], [[Type inference|partially inferred]]<br />
| scope = <br />
| platform = <br />
| operating system = <br />
| file ext = .C, .cc, .cpp, .cxx, {{nowrap|.c++}}, .h, .hh, .hpp, .hxx, {{nowrap|.h++}}<br />
| file format = <br />
| implementations = {{nowraplinks|[[Clang|LLVM Clang]], [[GNU Compiler Collection|GCC]], [[Microsoft Visual C++]], [[C++Builder|Embarcadero C++Builder]], [[Intel C++ Compiler]], [[IBM XL C++]], [[Edison Design Group|EDG]]}}<br />
| dialects = <br />
| influenced by = [[Ada (programming language)|Ada]], [[ALGOL 68]], [[C (programming language)|C]], [[CLU (programming language)|CLU]], [[ML (programming language)|ML]], [[Simula]]<br />
| influenced = [[Ada (programming language)|Ada 95]]<!-- 1995 -->, [[C Sharp (programming language)|C#]]<!-- 2001 -->,<ref name="influenceSharp">{{cite journal |last=Naugler |first=David |date=May 2007 |title=C# 2.0 for C++ and Java programmer: conference workshop |journal=Journal of Computing Sciences in Colleges |volume=22 |issue=5 |quote=Although C# has been strongly influenced by Java it has also been strongly influenced by C++ and is best viewed as a descendant of both C++ and Java.}}</ref> [[C99]]<!-- 1999 -->, [[Chapel (programming language)|Chapel]],<ref name="chplspec">{{cite web|title=Chapel spec (Acknowledgements)|url=https://chapel-lang.org/spec/spec-0.98.pdf|date=1 October 2015|accessdate=14 January 2016|publisher=Cray Inc}}</ref> [[Clojure]],<ref>{{cite web |url=http://www.codequarterly.com/2011/rich-hickey/ |archive-url=https://web.archive.org/web/20170111184835/http://www.codequarterly.com/2011/rich-hickey/ |url-status=dead |archive-date=2017-01-11 |title=Rich Hickey Q&A by Michael Fogus |access-date=2017-01-11}}</ref> [[D (programming language)|D]]<!-- 1999 -->, [[Java (programming language)|Java]]<!-- 1995 -->,<ref>{{cite web | url=https://books.google.com/books?id=0rUtBAAAQBAJ&lpg=PA133&pg=PA133#v=onepage&q&f=true|title=Cracking The Java Programming Interview :: 2000+ Java Interview Que/Ans |author=Harry. H. Chaudhary |accessdate=29 May 2016 |date=28 July 2014}}</ref> [[Lua (programming language)|Lua]]<!-- 1993 -->, [[Nim (programming language)|Nim]],{{citation needed|date=April 2017}} [[Perl]]<!-- 1987 -->, [[PHP]]<!-- 1995 -->, [[Python (programming language)|Python]],<ref>{{Cite web|url=https://docs.python.org/tutorial/classes.html|title=9. Classes — Python 3.6.4 documentation|website=docs.python.org|access-date=2018-01-09}}</ref> [[Rust (programming language)|Rust]], [[Seed7]]<br />
| wikibooks = C++ Programming<br />
}}<br />
<br />
A simple C++ Program:<br />
<br />
// A c++ program to vandalise wikipedia.<br />
* #include<iostream><br />
* #include <string><br />
<br />
* using namespace std;<br />
* int main(){<br />
* cout << "Fuiredai \n";<br />
* cout << "Willy on Wheels";<br />
* return 0;<br />
* }<br />
c<br />
'''C++''' ({{IPAc-en|ˌ|s|iː|ˌ|p|l|ʌ|s|ˈ|p|l|ʌ|s}}<!-- "cee" is the name of letter "c" -->) is a [[High-level programming language|high-level]], [[general-purpose programming language]] created by [[Bjarne Stroustrup]] as an extension of the [[C (programming language)|C programming language]], or "C with [[Class (programming)|Classes]]". The language has expanded significantly over time, and modern C++ has [[object-oriented programming|object-oriented]], [[generic programming|generic]], and [[functional programming|functional]] features in addition to facilities for [[Low-level programming language|low-level]] [[Memory (computing)|memory]] manipulation. It is almost always implemented as a [[compiled language]], and many vendors provide [[List of compilers#C.2B.2B compilers|C++ compilers]], including the [[Free Software Foundation]], [[LLVM]], [[Microsoft]], [[Intel]], [[Oracle Developer Studio|Oracle]], and [[IBM]], so it is available on many platforms.<ref name="stroustruptcpppl">{{Cite book |last=Stroustrup |first=Bjarne |authorlink=Bjarne Stroustrup |title=The C++ Programming Language |year=1997 |edition=Third |chapter=1 |isbn=0-201-88954-4 |oclc=59193992 |url=https://archive.org/details/cprogramminglang00stro_0 }}</ref><br />
<br />
C++ was designed with a bias toward [[system programming]] and [[embedded software|embedded]], resource-constrained software and large systems, with [[performance (software)|performance]], efficiency, and flexibility of use as its design highlights.<ref name=Stroustrup1>{{cite web|url=https://www.youtube.com/watch?v=86xWVb4XIyE|author=Stroustrup, B.|title=Lecture:The essence of C++. University of Edinburgh. |date=6 May 2014|accessdate=12 June 2015}}</ref> C++ has also been found useful in many other contexts, with key strengths being software infrastructure and resource-constrained applications,<ref name=Stroustrup1 /> including [[application software|desktop applications]], [[video games]], [[Server (computing)|servers]] (e.g. [[e-commerce]], [[Web search engine|Web search]], or [[SQL]] servers), and performance-critical applications (e.g. [[telephone switches]] or [[space probes]]).<ref name="applications">{{cite web |url=http://www.stroustrup.com/applications.html |title=C++ Applications |date=17 February 2014 |accessdate=5 May 2014 |first=Bjarne |last=Stroustrup |website=stroustrup.com}}</ref><br />
<br />
C++ is standardized by the [[International Organization for Standardization]] (ISO), with the latest standard version ratified and published by ISO in December 2017 as [[#Standardization|''ISO/IEC 14882:2017'']] (informally known as [[C++17]]).<ref name="isocpp2017"/> The C++ programming language was initially standardized in 1998 as ''ISO/IEC 14882:1998'', which was then amended by the [[C++03]], [[C++11]] and [[C++14]] standards. The current C++17 standard supersedes these with new features and an enlarged [[#Standard library|standard library]]. Before the initial standardization in 1998, C++ was developed by Danish computer scientist [[Bjarne Stroustrup]] at [[Bell Labs]] since 1979 as an extension of the [[C (programming language)|C language]]; he wanted an efficient and flexible language similar to C that also provided [[High-level programming language|high-level features]] for program organization.<ref>{{cite web |title=Bjarne Stroustrup's Homepage |url=http://www.stroustrup.com |website=www.stroustrup.com}}</ref> [[C++20]] is the next planned standard, keeping with the current trend of a new version every three years.<ref>{{cite web |title = C++; Where it's heading |url=https://dzone.com/articles/c-where-is-it-heading-and-what-are-the-new-feature}}</ref><br />
<br />
== History ==<br />
[[File:BjarneStroustrup.jpg|thumb|Bjarne Stroustrup, the creator of C++, in his AT&T New Jersey office c. 2000]]<br />
<br />
In 1979, [[Bjarne Stroustrup]], a Danish [[computer scientist]], began work on "{{visible anchor|C with [[Class (computer programming)|Classes]]}}", the predecessor to C++.<ref name="invention3">{{cite web |url = http://www.stroustrup.com/bs_faq.html#invention|title = Bjarne Stroustrup's FAQ: When was C++ invented?|first = Bjarne|last = Stroustrup|website = stroustrup.com|date = 7 March 2010|accessdate = 16 September 2010}}<br />
</ref> The motivation for creating a new language originated from Stroustrup's experience in programming for his PhD thesis. Stroustrup found that [[Simula]] had features that were very helpful for large software development, but the language was too slow for practical use, while [[BCPL]] was fast but too low-level to be suitable for large software development. When Stroustrup started working in [[AT&T Bell Labs]], he had the problem of analyzing the [[Unix|UNIX]] [[Kernel (computer science)|kernel]] with respect to [[distributed computing]]. Remembering his Ph.D. experience, Stroustrup set out to enhance the [[C (programming language)|C]] language with [[Simula]]-like features.<ref name="evolving">{{cite web |url = http://stroustrup.com/hopl-almost-final.pdf|title = Evolving a language in and for the real world: C++ 1991-2006|first = Bjarne|last = Stroustrup}}<br />
</ref> C was chosen because it was general-purpose, fast, portable and widely used. As well as C and Simula's influences, other languages also influenced this new language, including [[ALGOL 68]], [[Ada (programming language)|Ada]], [[CLU (programming language)|CLU]] and [[ML (programming language)|ML]].<br />
<br />
Initially, Stroustrup's "C with Classes" added features to the C compiler, Cpre, including [[class (computer programming)|classes]], [[derived class]]es, [[strong typing]], [[inlining]] and [[default argument]]s.<ref name="hopl2">{{cite web|last1=Stroustrup|first1=Bjarne|title=A History of C ++ : 1979− 1991|url=http://www.stroustrup.com/hopl2.pdf}}</ref><br />
<br />
In 1982, Stroustrup started to develop a successor to C with Classes, which he named "C++" (<syntaxhighlight lang="C++" inline>++</syntaxhighlight> being the [[increment operator]] in C) after going through several other names. New features were added, including [[virtual function]]s, function name and [[operator overloading]], references, constants, type-safe free-store memory allocation (new/delete), improved type checking, and BCPL style single-line comments with two forward slashes (<syntaxhighlight lang="C++" inline>//</syntaxhighlight>). Furthermore, Stroustrup developed a new, standalone compiler for C++, [[Cfront]].<br />
<br />
In 1985, the first edition of ''[[The C++ Programming Language]]'' was released, which became the definitive reference for the language, as there was not yet an official standard.<ref name="1st-edition3">{{cite web |url = http://www.stroustrup.com/1st.html|title = The C++ Programming Language|edition = First|first = Bjarne|last = Stroustrup|accessdate = 16 September 2010}}<br />
</ref> The first commercial implementation of C++ was released in October of the same year.<ref name="invention3"/><br />
<br />
In 1989, C++ 2.0 was released, followed by the updated second edition of ''The C++ Programming Language'' in 1991.<ref name="2nd-edition3">{{cite web |url = http://www.stroustrup.com/2nd.html|title = The C++ Programming Language|edition = Second|first = Bjarne|last = Stroustrup|accessdate = 16 September 2010}}</ref> New features in 2.0 included multiple inheritance, abstract classes, static member functions, [[const correctness|const member functions]], and protected members. In 1990, ''The Annotated C++ Reference Manual'' was published. This work became the basis for the future standard. Later feature additions included [[template (programming)|template]]s, [[exception handling|exceptions]], [[namespaces]], new [[cast (computer science)|cast]]s, and a [[Boolean datatype|Boolean type]].<br />
<br />
[[Image:20160121 CppFRUG Joel Falcou CppQuiz 3.jpg|thumb|left|A quiz on C++11 features being given in Paris in 2015]]<br />
<br />
In 1998, C++98 was released, standardizing the language, and a minor update ([[C++03]]) was released in 2003.<br />
<br />
After C++98, C++ evolved relatively slowly until, in 2011, the [[C++11]] standard was released, adding numerous new features, enlarging the standard library further, and providing more facilities to C++ programmers. After a minor [[C++14]] update released in December 2014, various new additions were introduced in [[C++17]], and further changes planned for 2020.<ref name="herbsutter.com">https://herbsutter.com/2016/06/30/trip-report-summer-iso-c-standards-meeting-oulu/ "the next standard after C++17 will be C++20"</ref><br />
<br />
As of 2019, C++ is now the fourth most popular programming language, behind [[Java (programming language)|Java]], C, and [[Python (programming language) |Python]].<ref>"Latest news." TIOBE Index | TIOBE - The Software Quality Company. N.p., n.d. Web. 5 June 2017.</ref><ref>Krill, Paul. "Java, C, C face growing competition in popularity." InfoWorld. InfoWorld, 10 February 2017. Web. 5 June 2017.</ref><br />
<br />
On January 3, 2018, Stroustrup was announced as the 2018 winner of the [[Charles Stark Draper Prize]] for Engineering, "for conceptualizing and developing the C++ programming language".<ref>https://www.nae.edu/177355.aspx "Computer Science Pioneer Bjarne Stroustrup to Receive the 2018 Charles Stark Draper Prize for Engineering"</ref><br />
{{clear}}<br />
<br />
=== Etymology ===<br />
According to Stroustrup, "the name signifies the evolutionary nature of the changes from C".<ref name="name">{{cite web |url=http://www.stroustrup.com/bs_faq.html#name |title=Bjarne Stroustrup's FAQ&nbsp;– Where did the name "C++" come from? |accessdate=16 January 2008 }}</ref> This name is credited to Rick Mascitti (mid-1983)<ref name="hopl2" /> and was first used in December 1983. When Mascitti was questioned informally in 1992 about the naming, he indicated that it was given in a [[tongue-in-cheek]] spirit. The name comes from C's <syntaxhighlight lang="C++" inline>++</syntaxhighlight> [[operator (programming)|operator]] (which [[increment and decrement operators|increments]] the [[value (computer science)|value]] of a [[variable (programming)|variable]]) and a common [[naming convention]] of using "+" to indicate an enhanced computer program.<br />
<br />
During C++'s development period, the language had been referred to as "new C" and "C with Classes"<ref name="hopl2" /><ref>{{cite web|title=C For C++ Programmers|url=https://www.ccs.neu.edu/course/com3620/parent/C-for-Java-C++/c-for-c++-alt.html|publisher=[[Northeastern University]]|accessdate=7 September 2015|archive-url=https://web.archive.org/web/20101117003419/http://www.ccs.neu.edu/course/com3620/parent/C-for-Java-C++/c-for-c++-alt.html|archive-date=17 November 2010|url-status=dead|df=dmy-all}}</ref> before acquiring its final name.<br />
<br />
=== Philosophy ===<br />
Throughout C++'s life, its development and evolution has been guided by a set of principles:<ref name="evolving"/><br />
<br />
* It must be driven by actual problems and its features should be immediately useful in real world programs.<br />
* Every feature should be implementable (with a reasonably obvious way to do so).<br />
* Programmers should be free to pick their own programming style, and that style should be fully supported by C++.<br />
* Allowing a useful feature is more important than preventing every possible misuse of C++.<br />
* It should provide facilities for organising programs into separate, well-defined parts, and provide facilities for combining separately developed parts.<br />
* No implicit violations of the [[type system]] (but allow explicit violations; that is, those explicitly requested by the programmer).<br />
* User-created types need to have the same support and performance as built-in types.<br />
* Unused features should not negatively impact created executables (e.g. in lower performance).<br />
* There should be no language beneath C++ (except [[assembly language]]).<br />
* C++ should work alongside other existing [[programming language]]s, rather than fostering its own separate and incompatible [[programming environment]].<br />
* If the programmer's intent is unknown, allow the programmer to specify it by providing manual control.<br />
<br />
=== Standardization ===<br />
[[Image:C++ Standards Committee meeting - July 1996 Stockholm - Wednesday general session.jpg|thumb|left|Scene during the C++ Standards Committee meeting in Stockholm in 1996]]<br />
{| class="wikitable floatright" style="margin-left: 1.5em;"<br />
|-<br />
! Year !! C++ Standard !! Informal name<br />
|-<br />
! 1998<br />
| | ISO/IEC 14882:1998<ref name="isocpp1998">{{cite web |title=ISO/IEC 14882:1998|publisher=International Organization for Standardization|url=https://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=25845 }}</ref> || C++98<br />
|-<br />
! 2003<br />
| | ISO/IEC 14882:2003<ref name="isocpp2003">{{cite web |title=ISO/IEC 14882:2003|publisher=International Organization for Standardization|url=https://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=38110 }}</ref> || [[C++03]]<br />
|-<br />
! 2011<br />
| | ISO/IEC 14882:2011<ref name="isocpp2011">{{cite web |title=ISO/IEC 14882:2011|publisher=International Organization for Standardization|url=https://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=50372 }}</ref> || [[C++11]], C++0x<br />
|-<br />
! 2014<br />
| | ISO/IEC 14882:2014<ref name="isocpp2014">{{cite web |title=ISO/IEC 14882:2014|publisher=International Organization for Standardization|url=https://www.iso.org/iso/home/store/catalogue_ics/catalogue_detail_ics.htm?csnumber=64029&ICS1=35&ICS2=60 }}</ref> || [[C++14]], C++1y<br />
|-<br />
! 2017<br />
| | ISO/IEC 14882:2017<ref name="isocpp2017">{{cite web |title=ISO/IEC 14882:2017|publisher=International Organization for Standardization|url=https://www.iso.org/standard/68564.html}}</ref> || [[C++17]], C++1z<br />
|-<br />
! 2020<br />
| | to be determined || [[C++20]],<ref name="herbsutter.com"/> C++2a<br />
|}<br />
<br />
C++ is standardized by an [[International Organization for Standardization|ISO]] working group known as [[ISO/IEC JTC 1/SC 22|JTC1/SC22/WG21]]. So far, it has published five revisions of the C++ standard and is currently working on the next revision, [[C++20]].<br />
<br />
In 1998, the ISO working group standardized C++ for the first time as ''ISO/IEC 14882:1998'', which is informally known as ''C++98''. In 2003, it published a new version of the C++ standard called ''ISO/IEC 14882:2003'', which fixed problems identified in C++98.<br />
<br />
The next major revision of the standard was informally referred to as "C++0x", but it was not released until 2011.<ref name="0xapprove">{{cite web|url=https://herbsutter.com/2011/08/12/we-have-an-international-standard-c0x-is-unanimously-approved/|title=We have an international standard: C++0x is unanimously approved|website=Sutter's Mill}}</ref> [[C++11]] (14882:2011) included many additions to both the core language and the standard library.<ref name="isocpp2011"/><br />
<br />
In 2014, [[C++14]] (also known as C++1y) was released as a small extension to [[C++11]], featuring mainly bug fixes and small improvements.<ref name="The Future of C">{{cite web|title=The Future of C++|url=https://channel9.msdn.com/Events/Build/2012/2-005}}</ref> The Draft International Standard ballot procedures completed in mid-August 2014.<ref>{{cite web|title=We have C++14! : Standard C++|url=https://isocpp.org/blog/2014/08/we-have-cpp14}}</ref><br />
<br />
After C++14, a major revision [[C++17]], informally known as C++1z, was completed by the ISO C++ Committee in mid July 2017 and was approved and published in December 2017.<ref name="Toronto meeting report">[https://herbsutter.com/2017/07/15/trip-report-summer-iso-c-standards-meeting-toronto/ Trip report: Summer ISO C++ standards meeting (Toronto)]</ref><br />
<br />
As part of the standardization process, ISO also publishes [[International Organization for Standardization#International Standards and other publications|technical reports and specifications]]:<br />
* ISO/IEC TR 18015:2006<ref>{{cite web|publisher=International Organization for Standardization|title=ISO/IEC TR 18015:2006|url=https://www.iso.org/standard/43351.html}}</ref> on the use of C++ in embedded systems and on performance implications of C++ language and library features,<br />
* ISO/IEC TR 19768:2007<ref>{{cite web|url=https://www.iso.org/standard/43289.html|title=ISO/IEC TR 19768:2007|publisher=International Organization for Standardization}}</ref> (also known as the [[C++ Technical Report 1]]) on library extensions mostly integrated into [[C++11]],<br />
* ISO/IEC TR 29124:2010<ref>{{cite web|url=https://www.iso.org/standard/50511.html|title=ISO/IEC TR 29124:2010|publisher=International Organization for Standardization}}</ref> on special mathematical functions,<br />
* ISO/IEC TR 24733:2011<ref>{{cite web|url=https://www.iso.org/standard/38843.html|title=ISO/IEC TR 24733:2011|publisher=International Organization for Standardization}}</ref> on [[decimal floating point]] arithmetic,<br />
* ISO/IEC TS 18822:2015<ref>{{cite web|url=https://www.iso.org/standard/63483.html|title=ISO/IEC TS 18822:2015|publisher=International Organization for Standardization}}</ref> on the standard filesystem library,<br />
* ISO/IEC TS 19570:2015<ref>{{cite web|url=https://www.iso.org/standard/65241.html|title=ISO/IEC TS 19570:2015|publisher=International Organization for Standardization}}</ref> on [[Parallel computing|parallel]] versions of the standard library algorithms,<br />
* ISO/IEC TS 19841:2015<ref>{{cite web|url=https://www.iso.org/standard/66343.html|title=ISO/IEC TS 19841:2015|publisher=International Organization for Standardization}}</ref> on software [[transactional memory]],<br />
* ISO/IEC TS 19568:2015<ref>{{cite web|url=https://www.iso.org/standard/65238.html|title=ISO/IEC TS 19568:2015|publisher=International Organization for Standardization}}</ref> on a new set of library extensions, some of which are already integrated into [[C++17]],<br />
* ISO/IEC TS 19217:2015<ref>{{cite web|url=https://www.iso.org/standard/64031.html|title=ISO/IEC TS 19217:2015|publisher=International Organization for Standardization}}</ref> on the C++ [[concepts (C++)|concepts]], integrated into [[C++20]]<br />
* ISO/IEC TS 19571:2016<ref>{{cite web|url=https://www.iso.org/standard/65242.html|title=ISO/IEC TS 19571:2016|publisher=International Organization for Standardization}}</ref> on the library extensions for concurrency<br />
* ISO/IEC TS 19568:2017<ref>{{cite web|url=https://www.iso.org/standard/70587.html|title=ISO/IEC TS 19568:2017|publisher=International Organization for Standardization}}</ref> on a new set of general-purpose library extensions<br />
* ISO/IEC TS 21425:2017<ref>{{cite web|url=https://www.iso.org/standard/70910.html|title=ISO/IEC TS 21425:2017|publisher=International Organization for Standardization}}</ref> on the library extensions for ranges, integrated into [[C++20]]<br />
* ISO/IEC TS 22277:2017<ref>{{cite web|url=https://www.iso.org/standard/73008.html|title=ISO/IEC TS 22277:2017|publisher=International Organization for Standardization}}</ref> on coroutines<br />
* ISO/IEC TS 19216:2018<ref>{{cite web|url=https://www.iso.org/standard/64030.html|title=ISO/IEC TS 19216:2018|publisher=International Organization for Standardization}}</ref> on the networking library<br />
* ISO/IEC TS 21544:2018<ref>{{cite web|url=https://www.iso.org/standard/71051.html|title=ISO/IEC TS 21544:2018|publisher=International Organization for Standardization}}</ref> on modules<br />
* ISO/IEC TS 19570:2018<ref>{{cite web|url=https://www.iso.org/standard/70588.html|title=ISO/IEC TS 19570:2018|publisher=International Organization for Standardization}}</ref> on a new set of library extensions for parallelism<br />
More technical specifications are in development and pending approval, including static reflection.<ref>See a list at https://en.cppreference.com/w/cpp/experimental visited 15 February 2019.</ref><br />
<br />
== Language ==<br />
[[Image:Соколова.jpg|thumb|right|A programmer writing a C++ main() function in 2018]]<br />
The C++ language has two main components: a direct mapping of hardware features provided primarily by the C subset, and zero-overhead abstractions based on those mappings. Stroustrup describes C++ as "a light-weight abstraction programming language [designed] for building and using efficient and elegant abstractions";<ref name="Stroustrup1" /> and "offering both hardware access and abstraction is the basis of C++. Doing it efficiently is what distinguishes it from other languages."<ref>{{cite web|url=https://www.infoq.com/news/2015/04/stroustrup-cpp17-interview|author=B. Stroustrup (interviewed by Sergio De Simone)|date=30 April 2015|accessdate=8 July 2015|title=Stroustrup: Thoughts on C++17 - An Interview}}</ref><br />
<br />
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]]:<ref>{{Cite book |first=Bjarne |last=Stroustrup |year=2000 |page=46 |title=The C++ Programming Language |edition=Special |publisher=Addison-Wesley |isbn=0-201-70073-5 }}</ref><ref>{{cite web |url=http://www.stroustrup.com/3rd_issues.html |title=Open issues for The C++ Programming Language (3rd Edition) |first=Bjarne |last=Stroustrup |postscript=. 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.}}</ref><br />
<br />
<!--<br />
<br />
***************************************************************<br />
*<br />
* PLEASE NOTE:<br />
*<br />
* BEFORE MAKING CHANGES to the "Hello World" example<br />
* please establish consensus by discussing your proposed changes<br />
* on the Talk page. This is not the place to "Be Bold"; this<br />
* has been discussed before at length.<br />
*<br />
* If you change the sample program without discussion, it will be<br />
* reverted within a few minutes.<br />
*<br />
* Yes, you could say "using namespace std;" or "using std::cout;".<br />
* Yes, you could use "std::endl" rather than "\n".<br />
* Yes, you could add "return 0;" at the end.<br />
* Yes, you could add "int argc, char ** argv" to main.<br />
* Yes, your ancient compiler might require "#include <iostream.h>".<br />
* Yes, you could use "printf" from the Standard C Library.<br />
*<br />
* But don't<br />
*<br />
* The latest consensus is ''not'' to make any of those changes.<br />
* This is the example "Hello, world!" by Bjarne Stroustrup,<br />
* the author of the C++ language, and is used in<br />
* his book, "The C++ Programming Language (3rd edition)".<br />
*<br />
***************************************************************<br />
<br />
--><source lang="cpp" line="1"><br />
#include <iostream><br />
<br />
int main()<br />
{<br />
std::cout << "Hello, world!\n";<br />
}<br />
</source><!--<br />
<br />
*** PLEASE NOTE:****<br />
* BEFORE MAKING CHANGES to the "Hello World" example<br />
* please establish consensus by discussing your proposed changes<br />
* on the Talk page. This is not the place to "Be Bold"; this<br />
* has been discussed before.<br />
*<br />
* If you change the sample program without discussion, it will be<br />
* reverted within a few minutes.<br />
*<br />
* Yes, you could say "using namespace std;" or "using std::cout;".<br />
* Yes, you could use "std::endl" rather than "\n".<br />
* Yes, you could add "return 0;" at the end.<br />
* Yes, you could add "int argc, char ** argv" to main.<br />
* Yes, your ancient compiler might require "#include <iostream.h>".<br />
* Yes, you could use "printf" from the Standard C Library.<br />
*<br />
* But don't.<br />
*<br />
* The latest consensus is ''not'' to make any of those changes.<br />
* This is the example "Hello, world!" by Bjarne Stroustrup,<br />
* the author of the C++ language, and is used in<br />
* his book, "The C++ Programming Language (3rd edition)".<br />
*<br />
*************************************************************** --><br />
<br />
=== Object storage ===<br />
As in C, C++ supports four types of [[memory management]]: static storage duration objects, thread storage duration objects, automatic storage duration objects, and dynamic storage duration objects.<ref name="C++11 3.7">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7 Storage duration [basic.stc]''</ref><br />
<br />
==== Static storage duration objects ====<br />
Static storage duration objects are created before <code>main()</code> is entered (see exceptions below) and destroyed in reverse order of creation after <code>main()</code> exits. The exact order of creation is not specified by the standard (though there are some rules defined below) to allow implementations some freedom in how to organize their implementation. More formally, objects of this type have a lifespan that "shall last for the duration of the program".<ref name="C++11 3.7.1">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.1 Static Storage duration [basic.stc.static]''</ref><br />
<br />
Static storage duration objects are initialized in two phases. First, "static initialization" is performed, and only ''after'' all static initialization is performed, "dynamic initialization" is performed. In static initialization, all objects are first initialized with zeros; after that, all objects that have a constant initialization phase are initialized with the constant expression (i.e. variables initialized with a literal or <code>constexpr</code>). Though it is not specified in the standard, the static initialization phase can be completed at compile time and saved in the data partition of the executable. Dynamic initialization involves all object initialization done via a constructor or function call (unless the function is marked with <code>constexpr</code>, in C++11). The dynamic initialization order is defined as the order of declaration within the compilation unit (i.e. the same file). No guarantees are provided about the order of initialization between compilation units.<br />
<br />
==== Thread storage duration objects ====<br />
Variables of this type are very similar to static storage duration objects. The main difference is the creation time is just prior to thread creation and destruction is done after the thread has been joined.<ref name="C++11 3.7.2">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.2 Thread Storage duration [basic.stc.thread]''</ref><br />
<br />
==== Automatic storage duration objects ====<br />
The most common variable types in C++ are local variables inside a function or block, and temporary variables.<ref name="C++11 3.7.3">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.3 Automatic Storage duration [basic.stc.auto]''</ref> The common feature about automatic variables is that they have a lifetime that is limited to the scope of the variable. They are created and potentially initialized at the point of declaration (see below for details) and destroyed in the ''reverse'' order of creation when the scope is left. This is implemented by allocation on the [[Stack-based memory allocation|stack]].<br />
<br />
Local variables are created as the point of execution passes the declaration point. If the variable has a constructor or initializer this is used to define the initial state of the object. Local variables are destroyed when the local block or function that they are declared in is closed. C++ destructors for local variables are called at the end of the object lifetime, allowing a discipline for automatic resource management termed [[Resource Acquisition Is Initialization|RAII]], which is widely used in C++.<br />
<br />
Member variables are created when the parent object is created. Array members are initialized from 0 to the last member of the array in order. Member variables are destroyed when the parent object is destroyed in the reverse order of creation. i.e. If the parent is an "automatic object" then it will be destroyed when it goes out of scope which triggers the destruction of all its members.<br />
<br />
Temporary variables are created as the result of expression evaluation and are destroyed when the statement containing the expression has been fully evaluated (usually at the <code>;</code> at the end of a statement).<br />
<br />
==== Dynamic storage duration objects ====<br />
{{Main|new and delete (C++)}}<br />
<br />
These objects have a dynamic lifespan and can be created directly with a call to {{cpp|new}} and destroyed explicitly with a call to {{cpp|delete}}.<ref name="C++11 3.7.4">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.4 Dynamic Storage duration <nowiki>[</nowiki>basic.stc.dynamic<nowiki>]</nowiki>''</ref> C++ also supports <code>malloc</code> and <code>free</code>, from C, but these are not compatible with {{cpp|new}} and {{cpp|delete}}. Use of {{cpp|new}} returns an address to the allocated memory. The C++ Core Guidelines advise against using {{cpp|new}} directly for creating dynamic objects in favor of smart pointers through {{cpp|make_unique<T>}} for single ownership and {{cpp|make_shared<T>}} for reference-counted multiple ownership,<ref>{{Cite web|url=https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r11-avoid-calling-new-and-delete-explicitly|title=C++ Core Guidelines|website=isocpp.github.io|access-date=2020-02-09}}</ref> which were introduced in C++11.<br />
<br />
=== Templates ===<br />
{{See also|Template metaprogramming|Generic programming}}<br />
<br />
[[C++ templates]] enable [[generic programming]]. C++ supports function, class, alias, and variable templates. Templates may be parameterized by types, compile-time constants, and other templates. Templates are implemented by ''instantiation'' at compile-time. To instantiate a template, compilers substitute specific arguments for a template's parameters to generate a concrete function or class instance. Some substitutions are not possible; these are eliminated by an overload resolution policy described by the phrase "[[Substitution failure is not an error]]" (SFINAE). Templates are a powerful tool that can be used for [[generic programming]], [[template metaprogramming]], and code optimization, but this power implies a cost. Template use may increase code size, because each template instantiation produces a copy of the template code: one for each set of template arguments, however, this is the same or smaller amount of code that would be generated if the code was written by hand.<ref name=":0" /> This is in contrast to run-time generics seen in other languages (e.g., [[Generics in Java|Java]]) where at compile-time the type is erased and a single template body is preserved.<br />
<br />
Templates are different from [[Macro (computer science)|macro]]s: while both of these compile-time language features enable conditional compilation, templates are not restricted to lexical substitution. Templates are aware of the semantics and type system of their companion language, as well as all compile-time type definitions, and can perform high-level operations including programmatic flow control based on evaluation of strictly type-checked parameters. Macros are capable of conditional control over compilation based on predetermined criteria, but cannot instantiate new types, recurse, or perform type evaluation and in effect are limited to pre-compilation text-substitution and text-inclusion/exclusion. In other words, macros can control compilation flow based on pre-defined symbols but cannot, unlike templates, independently instantiate new symbols. Templates are a tool for static [[Polymorphism in object-oriented programming|polymorphism]] (see below) and [[generic programming]].<br />
<br />
In addition, templates are a compile time mechanism in C++ that is [[Turing-complete]], meaning that any computation expressible by a computer program can be computed, in some form, by a [[template metaprogramming|template metaprogram]] prior to runtime.<br />
<br />
In summary, a template is a compile-time parameterized function or class written without knowledge of the specific arguments used to instantiate it. After instantiation, the resulting code is equivalent to code written specifically for the passed arguments. In this manner, templates provide a way to decouple generic, broadly applicable aspects of functions and classes (encoded in templates) from specific aspects (encoded in template parameters) without sacrificing performance due to abstraction.<br />
<br />
=== Objects ===<br />
{{Main|C++ classes}}<br />
<br />
C++ introduces [[object-oriented programming]] (OOP) features to C. It offers [[class (computer science)|class]]es, which provide the four features commonly present in OOP (and some non-OOP) languages: [[Abstraction (computer science)|abstraction]], [[Information hiding|encapsulation]], [[Inheritance (object-oriented programming)|inheritance]], and [[Polymorphism (computer science)|polymorphism]]. One distinguishing feature of C++ classes compared to classes in other programming languages is support for deterministic [[destructor (computer science)|destructors]], which in turn provide support for the [[Resource Acquisition is Initialization]] (RAII) concept.<br />
<br />
==== Encapsulation ====<br />
[[Information hiding|Encapsulation]] is the hiding of information to ensure that data structures and operators are used as intended and to make the usage model more obvious to the developer. C++ provides the ability to define classes and functions as its primary encapsulation mechanisms. Within a class, members can be declared as either public, protected, or private to explicitly enforce encapsulation. A public member of the class is accessible to any function. A private member is accessible only to functions that are members of that class and to functions and classes explicitly granted access permission by the class ("friends"). A protected member is accessible to members of classes that inherit from the class in addition to the class itself and any friends.<br />
<br />
The object-oriented principle ensures the encapsulation of all and only the functions that access the internal representation of a type. C++ supports this principle via member functions and friend functions, but it does not enforce it. Programmers can declare parts or all of the representation of a type to be public, and they are allowed to make public entities not part of the representation of a type. Therefore, C++ supports not just object-oriented programming, but other decomposition paradigms such as [[Modularity (programming)|modular programming]].<br />
<br />
It is generally considered good practice to make all [[data]] private or protected, and to make public only those functions that are part of a minimal interface for users of the class. This can hide the details of data implementation, allowing the designer to later fundamentally change the implementation without changing the interface in any way.<ref name="cppcs">{{Cite book |first1=Herb |last1=Sutter |first2=Andrei |last2=Alexandrescu |authorlink1=Herb Sutter |authorlink2=Andrei Alexandrescu |year=2004 |title=C++ Coding Standards: 101 Rules, Guidelines, and Best Practices |publisher = Addison-Wesley }}</ref><ref name="industrialcpp">{{Cite book |last1=Henricson |first1=Mats |last2=Nyquist |first2=Erik |title=Industrial Strength C++ |publisher=Prentice Hall |year=1997 |isbn=0-13-120965-5 |url=https://archive.org/details/industrialstreng0000henr }}</ref><br />
<br />
==== Inheritance ====<br />
[[Inheritance (computer science)|Inheritance]] allows one data type to acquire properties of other data types. Inheritance from a [[base class]] may be declared as public, protected, or private. This access specifier determines whether unrelated and derived classes can access the inherited public and protected members of the base class. Only public inheritance corresponds to what is usually meant by "inheritance". The other two forms are much less frequently used. If the access specifier is omitted, a "class" inherits privately, while a "struct" inherits publicly. Base classes may be declared as virtual; this is called [[virtual inheritance]]. Virtual inheritance ensures that only one instance of a base class exists in the inheritance graph, avoiding some of the ambiguity problems of multiple inheritance.<br />
<br />
[[Multiple inheritance]] is a C++ feature not found in most other languages, allowing a class to be derived from more than one base class; this allows for more elaborate inheritance relationships. For example, a "Flying Cat" class can inherit from both "Cat" and "Flying Mammal". Some other languages, such as [[C Sharp (programming language)|C#]] or [[Java (programming language)|Java]], accomplish something similar (although more limited) by allowing inheritance of multiple [[Interface (computer science)|interfaces]] while restricting the number of base classes to one (interfaces, unlike classes, provide only declarations of member functions, no implementation or member data). An interface as in C# and Java can be defined in C++ as a class containing only pure virtual functions, often known as an [[abstract base class]] or "ABC". The member functions of such an abstract base class are normally explicitly defined in the derived class, not inherited implicitly. C++ virtual inheritance exhibits an ambiguity resolution feature called [[Dominance (C++)|dominance]].<br />
<br />
=== Operators and operator overloading ===<br />
{| class="wikitable" style="float: right; margin: 0.5em 0 1em 2em;"<br />
|+ Operators that cannot be overloaded<br />
! style="text-align: center" | Operator<br />
! style="width: 9em" | Symbol<br />
|-<br />
! style="text-align: center" | Scope resolution operator<br />
| {{C-lang| ::}}<br />
|-<br />
! style="text-align: center" | Conditional operator<br />
| {{C-lang| ?:}}<br />
|-<br />
! style="text-align: center" | dot operator<br />
| {{C-lang| .}}<br />
|-<br />
<br />
|-<br />
! style="text-align: center" | Member selection operator<br />
| {{C-lang| .*}}<br />
|-<br />
! style="text-align: center" | "sizeof" operator<br />
| {{C-lang| sizeof}}<br />
|-<br />
! style="text-align: center" | "typeid" operator<br />
| {{C-lang| typeid}}<br />
|}<br />
{{Main|Operators in C and C++}}<br />
C++ provides more than 35 operators, covering basic arithmetic, bit manipulation, indirection, comparisons, logical operations and others. Almost all operators can be [[Operator overloading|overloaded]] for user-defined types, with a few notable exceptions such as member access (<code>.</code> and <code>.*</code>) as well as the conditional operator. The rich set of overloadable operators is central to making user-defined types in C++ seem like built-in types.<br />
<br />
Overloadable operators are also an essential part of many advanced C++ programming techniques, such as [[smart pointer]]s. Overloading an operator does not change the precedence of calculations involving the operator, nor does it change the number of operands that the operator uses (any operand may however be ignored by the operator, though it will be evaluated prior to execution). Overloaded "<code>&&</code>" and "<code>||</code>" operators lose their [[short-circuit evaluation]] property.<br />
<br />
=== Polymorphism ===<br />
{{See also|Polymorphism (computer science)}}<br />
<br />
[[Type polymorphism|Polymorphism]] enables one common interface for many implementations, and for objects to act differently under different circumstances.<br />
<br />
C++ supports several kinds of ''static'' (resolved at [[compile-time]]) and ''dynamic'' (resolved at [[Run time (program lifecycle phase)|run-time]]) [[polymorphism (computer science)|polymorphism]]s, supported by the language features described above. [[Compile-time polymorphism]] does not allow for certain run-time decisions, while [[runtime polymorphism]] typically incurs a performance penalty.<br />
<br />
==== Static polymorphism ====<br />
{{See also|Parametric polymorphism|ad hoc polymorphism}}<br />
<br />
[[Function overloading]] allows programs to declare multiple functions having the same name but with different arguments (i.e. [[ad hoc polymorphism|''ad hoc'' polymorphism]]). The functions are distinguished by the number or types of their [[Parameter (computer science)|formal parameter]]s. Thus, the same function name can refer to different functions depending on the context in which it is used. The type returned by the function is not used to distinguish overloaded functions and would result in a compile-time error message.<br />
<br />
When declaring a function, a programmer can specify for one or more parameters a [[default arguments|default value]]. Doing so allows the parameters with defaults to optionally be omitted when the function is called, in which case the default arguments will be used. When a function is called with fewer arguments than there are declared parameters, explicit arguments are matched to parameters in left-to-right order, with any unmatched parameters at the end of the parameter list being assigned their default arguments. In many cases, specifying default arguments in a single function declaration is preferable to providing overloaded function definitions with different numbers of parameters.<br />
<br />
[[Generic programming#Templates|Templates]] in C++ provide a sophisticated mechanism for writing generic, polymorphic code (i.e. [[parametric polymorphism]]). In particular, through the [[curiously recurring template pattern]], it's possible to implement a form of static polymorphism that closely mimics the syntax for overriding virtual functions. Because C++ templates are type-aware and [[Turing-complete]], they can also be used to let the compiler resolve recursive conditionals and generate substantial programs through [[template metaprogramming]]. Contrary to some opinion, template code will not generate a bulk code after compilation with the proper compiler settings.<ref name=":0">{{cite web |accessdate=8 March 2010 |publisher=EmptyCrate Software. Travel. Stuff. |location=articles.emptycrate.com/ |title=Nobody Understands C++: Part 5: Template Code Bloat |date=6 May 2008 |url=https://articles.emptycrate.com/2008/05/06/nobody_understands_c_part_5_template_code_bloat.html |quote=On occasion you will read or hear someone talking about C++ templates causing code bloat. I was thinking about it the other day and thought to myself, "self, if the code does exactly the same thing then the compiled code cannot really be any bigger, can it?" [...] And what about compiled code size? Each were compiled with the command g++ <filename>.cpp -O3. Non-template version: 8140 bytes, template version: 8028 bytes! }}</ref><br />
<br />
==== Dynamic polymorphism ====<br />
<br />
===== Inheritance =====<br />
{{See also|Subtyping}}<br />
<br />
Variable pointers and references to a base class type in C++ can also refer to objects of any derived classes of that type. This allows arrays and other kinds of containers to hold pointers to objects of differing types (references cannot be directly held in containers). This enables dynamic (run-time) polymorphism, where the referred objects can behave differently, depending on their (actual, derived) types.<br />
<br />
C++ also provides the <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> operator, which allows code to safely attempt conversion of an object, via a base reference/pointer, to a more derived type: ''downcasting''. The ''attempt'' is necessary as often one does not know which derived type is referenced. (''Upcasting'', conversion to a more general type, can always be checked/performed at compile-time via <syntaxhighlight lang="C++" inline>static_cast</syntaxhighlight>, as ancestral classes are specified in the derived class's interface, visible to all callers.) <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> relies on [[run-time type information]] (RTTI), metadata in the program that enables differentiating types and their relationships. If a <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> to a pointer fails, the result is the <syntaxhighlight lang="C++" inline>nullptr</syntaxhighlight> constant, whereas if the destination is a reference (which cannot be null), the cast throws an exception. Objects ''known'' to be of a certain derived type can be cast to that with <syntaxhighlight lang="C++" inline>static_cast</syntaxhighlight>, bypassing RTTI and the safe runtime type-checking of <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight>, so this should be used only if the programmer is very confident the cast is, and will always be, valid.<br />
<br />
===== Virtual member functions =====<br />
Ordinarily, when a function in a derived class [[Method overriding (programming)|overrides]] a function in a base class, the function to call is determined by the type of the object. A given function is overridden when there exists no difference in the number or type of parameters between two or more definitions of that function. Hence, at compile time, it may not be possible to determine the type of the object and therefore the correct function to call, given only a base class pointer; the decision is therefore put off until runtime. This is called [[dynamic dispatch]]. [[virtual functions|Virtual member functions]] or ''methods''<ref>{{Cite book |quote=A virtual member function is sometimes called a ''method''. |first=Bjarne |last=Stroustrup |year=2000 |page=310 |title=The C++ Programming Language |edition=Special |publisher=Addison-Wesley |isbn = 0-201-70073-5 }}</ref> allow the most specific implementation of the function to be called, according to the actual run-time type of the object. In C++ implementations, this is commonly done using [[virtual function table]]s. If the object type is known, this may be bypassed by prepending a [[fully qualified name|fully qualified class name]] before the function call, but in general calls to virtual functions are resolved at run time.<br />
<br />
In addition to standard member functions, operator overloads and destructors can be virtual. As a rule of thumb, if any function in the class is virtual, the destructor should be as well. As the type of an object at its creation is known at compile time, constructors, and by extension copy constructors, cannot be virtual. Nonetheless a situation may arise where a copy of an object needs to be created when a pointer to a derived object is passed as a pointer to a base object. In such a case, a common solution is to create a <syntaxhighlight lang="C++" inline>clone()</syntaxhighlight> (or similar) virtual function that creates and returns a copy of the derived class when called.<br />
<br />
A member function can also be made "pure virtual" by appending it with <syntaxhighlight lang="C++" inline>= 0</syntaxhighlight> after the closing parenthesis and before the semicolon. A class containing a pure virtual function is called an ''abstract class''. Objects cannot be created from an abstract class; they can only be derived from. Any derived class inherits the virtual function as pure and must provide a non-pure definition of it (and all other pure virtual functions) before objects of the derived class can be created. A program that attempts to create an object of a class with a pure virtual member function or inherited pure virtual member function is ill-formed.<br />
<br />
=== Lambda expressions ===<br />
C++ provides support for [[anonymous function]]s, also known as lambda expressions, with the following form:<br />
<br />
<source lang="cpp"><br />
[capture](parameters) -> return_type { function_body }<br />
</source><br />
<br />
The return type of a lambda expression can also be automatically inferred, if possible, e.g.:<br />
<br />
<source lang="cpp"><br />
[](int x, int y) { return x - y; } // inferred<br />
[](int x, int y) -> int { return x + y; } // explicit<br />
</source><br />
<br />
The <syntaxhighlight lang="C++" inline>[capture]</syntaxhighlight> list supports the definition of [[Closure (computer programming)|closures]]. Such lambda expressions are defined in the standard as [[syntactic sugar]] for an unnamed [[function object]].<br />
<br />
=== Exception handling ===<br />
Exception handling is used to communicate the existence of a runtime problem or error from where it was detected to where the issue can be handled.<ref>{{Cite web|url = http://www.cl.cam.ac.uk/teaching/1314/CandC++/lecture7.pdf|title = <nowiki>C and C++ Exceptions | Templates</nowiki>|date = 2013|accessdate = 30 August 2016|website = Cambridge Computer Laboratory - Course Materials 2013-14|publisher = |last = Mycroft|first = Alan}}</ref> It permits this to be done in a uniform manner and separately from the main code, while detecting all errors.<ref name="exception_summary">{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 345}}</ref> Should an error occur, an exception is thrown (raised), which is then caught by the nearest suitable exception handler. The exception causes the current scope to be exited, and also each outer scope (propagation) until a suitable handler is found, calling in turn the destructors of any objects in these exited scopes.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 363–365}}</ref> At the same time, an exception is presented as an object carrying the data about the detected problem.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 345, 363}}</ref><br />
<br />
Some C++ style guides, such as Google's,<ref>{{cite web |title=Google C++ Style Guide |url=https://google.github.io/styleguide/cppguide.html#Exceptions |accessdate=25 June 2019}}</ref> LLVM's,<ref>{{cite web |title=LLVM Coding Standards |url=https://llvm.org/docs/CodingStandards.html#do-not-use-rtti-or-exceptions |website=LLVM 9 documentation |accessdate=25 June 2019}}</ref> and Qt's<ref>{{cite web |title=Coding Conventions |url=https://wiki.qt.io/Coding_Conventions |website=Qt Wiki |accessdate=26 June 2019}}</ref> forbid the usage of exceptions.<br />
<br />
The exception-causing code is placed inside a <syntaxhighlight lang="C++" inline>try</syntaxhighlight> block. The exceptions are handled in separate <syntaxhighlight lang="C++" inline>catch</syntaxhighlight> blocks (the handlers); each <syntaxhighlight lang="C++" inline>try</syntaxhighlight> block can have multiple exception handlers, as it is visible in the example below.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 344, 370}}</ref><br />
<!--"#include <iostream.h> is deprecated"--><br />
<source lang="cpp" line="1"><br />
#include <iostream><br />
#include <vector><br />
#include <stdexcept><br />
<br />
int main() {<br />
try {<br />
std::vector<int> vec{3, 4, 3, 1};<br />
int i{vec.at(4)}; // Throws an exception, std::out_of_range (indexing for vec is from 0-3 not 1-4)<br />
}<br />
// An exception handler, catches std::out_of_range, which is thrown by vec.at(4)<br />
catch (std::out_of_range &e) {<br />
std::cerr << "Accessing a non-existent element: " << e.what() << '\n';<br />
}<br />
// To catch any other standard library exceptions (they derive from std::exception)<br />
catch (std::exception &e) {<br />
std::cerr << "Exception thrown: " << e.what() << '\n';<br />
}<br />
// Catch any unrecognised exceptions (i.e. those which don't derive from std::exception)<br />
catch (...) {<br />
std::cerr << "Some fatal error\n";<br />
}<br />
}<br />
</source><br />
<br />
It is also possible to raise exceptions purposefully, using the <syntaxhighlight lang="C++" inline>throw</syntaxhighlight> keyword; these exceptions are handled in the usual way. In some cases, exceptions cannot be used due to technical reasons. One such example is a critical component of an embedded system, where every operation must be guaranteed to complete within a specified amount of time. This cannot be determined with exceptions as no tools exist to determine the maximum time required for an exception to be handled.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 349}}</ref><br />
<br />
Unlike [[Signal handler|signal handling]], in which the handling function is called from the point of failure, exception handling exits the current scope before the catch block is entered, which may be located in the current function or any of the previous function calls currently on the stack.<br />
<br />
== Standard library ==<br />
[[Image:ANSI ISO C++ WP.jpg|thumb|right|The draft "Working Paper" standard that became approved as C++98; half of its size was devoted to the C++ Standard Library]]<br />
{{Main|C++ Standard Library}}<br />
The C++ [[standardization|standard]] consists of two parts: the core language and the standard library. C++ programmers expect the latter on every major implementation of C++; it includes aggregate types ([[sequence container (C++)#Vector|vectors]], lists, maps, sets, queues, stacks, arrays, tuples), [[algorithm]]s (find, [[Foreach loop|for_each]], [[Binary search algorithm|binary_search]], random_shuffle, etc.), input/output facilities ([[iostream]], for reading from and writing to the console and files), filesystem library, localisation support, [[smart pointers]] for automatic memory management, [[regular expression]] support, [[multithreading (software)|multi-threading]] library, atomics support (allowing a variable to be read or written to by at most one thread at a time without any external synchronisation), time utilities (measurement, getting current time, etc.), a system for converting error reporting that doesn't use C++ [[exception handling|exceptions]] into C++ exceptions, a [[random number generator]] and a slightly modified version of the [[C standard library]] (to make it comply with the C++ type system).<br />
<br />
A large part of the C++ library is based on the [[Standard Template Library]] (STL). Useful tools provided by the STL include [[container (data structure)|container]]s as the collections of objects (such as [[array data structure|vector]]s and [[linked list|lists]]), [[iterator]]s that provide array-like access to containers, and [[algorithm]]s that perform operations such as searching and sorting.<br />
<br />
Furthermore, (multi)maps ([[associative array]]s) and (multi)sets are provided, all of which export compatible interfaces. Therefore, using templates it is possible to write generic algorithms that work with any container or on any sequence defined by iterators. As in C, the [[feature (software design)|feature]]s of the [[library (computing)|library]] are accessed by using the <syntaxhighlight lang="C++" inline>#include</syntaxhighlight> [[directive (programming)|directive]] to include a [[standard header]]. The [[C++ Standard Library]] provides 105 standard headers, of which 27 are deprecated.<br />
<br />
The standard incorporates the STL that was originally designed by [[Alexander Stepanov]], who experimented with generic algorithms and containers for many years. When he started with C++, he finally found a language where it was possible to create generic algorithms (e.g., STL sort) that perform even better than, for example, the C standard library qsort, thanks to C++ features like using inlining and compile-time binding instead of function pointers. The standard does not refer to it as "STL", as it is merely a part of the standard library, but the term is still widely used to distinguish it from the rest of the standard library (input/output streams, internationalization, diagnostics, the C library subset, etc.).<ref>{{cite web|url=http://www.stlport.org/resources/StepanovUSA.html |author=Graziano Lo Russo |title=An Interview with A. Stepanov |year=2008 |accessdate=8 October 2015 |website=stlport.org}}</ref><br />
<br />
Most C++ compilers, and all major ones, provide a standards-conforming implementation of the C++ standard library.<br />
<br />
== Compatibility ==<br />
To give compiler vendors greater freedom, the C++ standards committee decided not to dictate the implementation of [[name mangling]], [[exception handling]], and other implementation-specific features. The downside of this decision is that [[object code]] produced by different [[compiler]]s is expected to be incompatible. There were, however, attempts to standardize compilers for particular machines or [[operating system]]s (for example C++ ABI),<ref>{{cite web |url=https://mentorembedded.github.io/cxx-abi/ |title=C++ ABI Summary |date=20 March 2001 |accessdate=30 May 2006 }}</ref> though they seem to be largely abandoned now.<br />
<br />
=== With C ===<br />
[[Image:C slash cpp.svg|thumb|right|upright=0.6|The relationship of C++ to C has always been a bit problematic]]<br />
{{Details|Compatibility of C and C++}}<br />
<br />
C++ is often considered to be a superset of [[C (programming language)|C]] but this is not strictly true.<ref name="superset">{{cite web |url=http://www.stroustrup.com/bs_faq.html#C-is-subset |title=Bjarne Stroustrup's FAQ&nbsp;– Is C a subset of C++? |accessdate=5 May 2014}}</ref> Most C code can easily be made to compile correctly in C++ but there are a few differences that cause some valid C code to be invalid or behave differently in C++. For example, C allows implicit conversion from <syntaxhighlight lang="C++" inline>void*</syntaxhighlight> to other pointer types but C++ does not (for type safety reasons). Also, C++ defines many new keywords, such as <syntaxhighlight lang="C++" inline>new</syntaxhighlight> and <syntaxhighlight lang="C++" inline>class</syntaxhighlight>, which may be used as identifiers (for example, variable names) in a C program.<br />
<br />
Some incompatibilities have been removed by the 1999 revision of the C standard ([[C99]]), which now supports C++ features such as line comments (<syntaxhighlight lang="C++" inline>//</syntaxhighlight>) and declarations mixed with code. On the other hand, C99 introduced a number of new features that C++ did not support that were incompatible or redundant in C++, such as [[variable-length array]]s, native complex-number types (however, the <syntaxhighlight lang="C++" inline>std::complex</syntaxhighlight> class in the C++ standard library provides similar functionality, although not code-compatible), designated initializers, [[C syntax#Compound literals|compound literals]], and the <syntaxhighlight lang="C++" inline>restrict</syntaxhighlight> keyword.<ref>{{cite web |url=http://home.datacomm.ch/t_wolf/tw/c/c9x_changes.html |title=C9X – The New C Standard |accessdate=27 December 2008 }}</ref> Some of the C99-introduced features were included in the subsequent version of the C++ standard, [[C++11#Improved C compatibility|C++11]] (out of those which were not redundant).<ref>{{cite web |title=C++0x Support in GCC |url=https://gcc.gnu.org/projects/cxx0x.html |accessdate=12 October 2010}}</ref><ref>{{cite web |title=C++0x Core Language Features In VC10: The Table |url=https://blogs.msdn.com/b/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx |accessdate=12 October 2010 }}</ref><ref>{{cite web|url=https://clang.llvm.org/cxx_status.html |title=Clang - C++98, C++11, and C++14 Status |publisher=Clang.llvm.org |date=12 May 2013 |accessdate=10 June 2013}}</ref> However, the C++11 standard introduces new incompatibilities, such as disallowing assignment of a string literal to a character pointer, which remains valid C.<br />
<br />
To intermix C and C++ code, any function declaration or definition that is to be called from/used both in C and C++ must be declared with C linkage by placing it within an <syntaxhighlight style=white-space:nowrap lang="C++" inline>extern "C" {/*...*/}</syntaxhighlight> block. Such a function may not rely on features depending on [[name mangling]] (i.e., function overloading).<br />
<br />
== Criticism ==<br />
{{Main|Criticism of C++}}<br />
<br />
Despite its widespread adoption, some notable programmers have criticized the C++ language, including [[Linus Torvalds]],<ref name=torvalds>{{cite mailing list |url=https://lwn.net/Articles/249460/ |title=Re: [RFC] Convert builin-mailinfo.c to use The Better String Library |date=6 September 2007 |accessdate=31 March 2015 }}</ref> [[Richard Stallman]],<ref>{{cite mailing list |url=http://harmful.cat-v.org/software/c++/rms |title=Re: Efforts to attract more users? |date=12 July 2010 |accessdate=31 March 2015 }}</ref> [[Joshua Bloch]], [[Ken Thompson]],<ref>{{cite web |url=https://www.drdobbs.com/open-source/interview-with-ken-thompson/229502480 |title=Dr. Dobb's: Interview with Ken Thompson |author=Andrew Binstock |date=18 May 2011 |accessdate=7 February 2014}}</ref><ref name="Seibel2009">{{cite book|author=Peter Seibel|title=Coders at Work: Reflections on the Craft of Programming|url=https://books.google.com/books?id=nneBa6-mWfgC&pg=PA475|date=16 September 2009|publisher=Apress|isbn=978-1-4302-1948-4|pages=475–476}}</ref><ref name="gigamonkeysWordpress">https://gigamonkeys.wordpress.com/2009/10/16/coders-c-plus-plus/</ref> and [[Donald Knuth]].<ref name="dobbsKnuth">https://www.drdobbs.com/architecture-and-design/an-interview-with-donald-knuth/228700500</ref><ref name="knuth1993">http://tex.loria.fr/litte/knuth-interview</ref><br />
<br />
One of the most often criticised points of C++ is its perceived complexity as a language, with the criticism that a large number of non-orthogonal features in practice necessitates restricting code to subset of C++, thus eschewing the readability benefits of common style and idioms. As expressed by [[Joshua Bloch]]: <blockquote> I think C++ was pushed well beyond its complexity threshold, and yet there are a lot of people programming it. But what you do is you force people to subset it. So almost every shop that I know of that uses C++ says, “Yes, we’re using C++ but we’re not doing multiple-implementation inheritance and we’re not using operator overloading.” There are just a bunch of features that you’re not going to use because the complexity of the resulting code is too high. And I don’t think it’s good when you have to start doing that. You lose this programmer portability where everyone can read everyone else’s code, which I think is such a good thing. </blockquote><br />
<br />
[[Donald Knuth]] (1993, commenting on pre-standardized C++), who said of [[Edsger Dijkstra]] that "to think of programming in C++" "would make him physically ill":<ref name="dobbsKnuth" /><ref name="knuth1993" /> <blockquote> The problem that I have with them today is that... C++ is too complicated. At the moment, it's impossible for me to write portable code that I believe would work on lots of different systems, unless I avoid all exotic features. Whenever the C++ language designers had two competing ideas as to how they should solve some problem, they said "OK, we'll do them both". So the language is too baroque for my taste. </blockquote><br />
<br />
[[Ken Thompson]], who was a colleague of Stroustrup at Bell Labs, gives his assessment:<ref name="Seibel2009" /><ref name="gigamonkeysWordpress" /> <blockquote> It certainly has its good points. But by and large I think it’s a bad language. It does a lot of things half well and it’s just a garbage heap of ideas that are mutually exclusive. Everybody I know, whether it’s personal or corporate, selects a subset and these subsets are different. So it’s not a good language to transport an algorithm—to say, “I wrote it; here, take it.” It’s way too big, way too complex. And it’s obviously [[Design by committee|built by a committee]]. <br />
Stroustrup campaigned for years and years and years, way beyond any sort of technical contributions he made to the language, to get it adopted and used. And he sort of ran all the standards committees with a whip and a chair. And he said “no” to no one. He put every feature in that language that ever existed. It wasn’t cleanly designed—it was just the union of everything that came along. And I think it suffered drastically from that. </blockquote><br />
<br />
However [[Brian Kernighan]], also a colleague at Bell Labs, disputes this assessment:<ref>{{cite video|people=Brian Kernighan|date=July 18, 2018|title=Brian Kernighan Q&A - Computerphile|url=https://www.youtube.com/watch?v=zmYhR8cUX90&t=5m17s}}</ref> <blockquote>C++ has been enormously influential. ... Lots of people say C++ is too big and too complicated etc. etc. but in fact it is a very powerful language and pretty much everything that is in there is there for a really sound reason: it is not somebody doing random invention, it is actually people trying to solve real world problems. Now a lot of the programs that we take for granted today, that we just use, are C++ programs. </blockquote><br />
<br />
Stroustrup himself comments that C++ semantics are much cleaner than its syntax: "within C++, there is a much smaller and cleaner language struggling to get out".<ref>http://www.stroustrup.com/bs_faq.html#really-say-that</ref><br />
<br />
Other complaints may include a lack of [[reflection (computer programming)|reflection]] or [[garbage collection (computer science)|garbage collection]], long compilation times, perceived [[feature creep]],<ref>{{cite web |url=https://commandcenter.blogspot.mx/2012/06/less-is-exponentially-more.html |title=Less is exponentially more |year=2012 |last=Pike |first=Rob}}</ref> and verbose error messages, particularly from template metaprogramming.<ref>{{cite web|url=https://yosefk.com/c++fqa/defective.html|title=Defective C++|first=Yossi|last=Kreinin|date=13 October 2009|accessdate=3 February 2016}}</ref><br />
<br />
== See also ==<br />
{{Portal|Computer programming}}<br />
* [[Comparison of programming languages]]<br />
* [[List of C++ compilers]]<br />
* [[Outline of C++]]<br />
* [[:Category:C++ libraries|C++ Libraries (category)]]<br />
<br />
== References ==<br />
{{Reflist|30em}}<br />
<br />
== Further reading ==<br />
{{Refbegin|30em}}<br />
* {{Cite book |first=David |last=Abrahams |authorlink=David Abrahams (computer programmer) |first2=Aleksey |last2=Gurtovoy |title=C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond |publisher=Addison-Wesley |isbn=0-321-22725-5 }}<br />
* {{Cite book |first=Andrei |last=Alexandrescu |authorlink=Andrei Alexandrescu |year=2001 |title=Modern C++ Design: Generic Programming and Design Patterns Applied |publisher=Addison-Wesley |isbn=0-201-70431-5 }}<br />
* {{Cite book |first=Andrei |last=Alexandrescu |authorlink=Andrei Alexandrescu |first2=Herb |last2=Sutter |authorlink2=Herb Sutter|year=2004 |title=C++ Design and Coding Standards: Rules and Guidelines for Writing Programs |publisher=Addison-Wesley |isbn=0-321-11358-6 }}<br />
* {{Cite book |first=Pete |last=Becker |authorlink=Pete Becker |year=2006 |title=The C++ Standard Library Extensions : A Tutorial and Reference |publisher=Addison-Wesley |isbn=0-321-41299-0 }}<br />
* {{Cite book |first=Frank |last=Brokken |year=2010 |title=C++ Annotations |publisher=University of Groningen |isbn=90-367-0470-7 |url=http://www.icce.rug.nl/documents/cplusplus/ }}<br />
* {{Cite book |first=James O. |last=Coplien |authorlink=James O. Coplien |origyear=reprinted with corrections, original year of publication 1992 |date=1994 |title=Advanced C++: Programming Styles and Idioms |isbn=0-201-54855-0 |url=https://archive.org/details/advancedcbsprogr00copl }}<br />
* {{Cite book |first=Stephen C. |last=Dewhurst |year=2005 |title=C++ Common Knowledge: Essential Intermediate Programming |publisher=Addison-Wesley |isbn=0-321-32192-8 }}<br />
* {{Cite book |author=Information Technology Industry Council |authorlink=Information and Communications Technology Council |publisher=ISO/IEC |location=Geneva |title=Programming languages&nbsp;– C++ |id=14882:2003(E) |edition=Second |date=15 October 2003 }}<br />
* {{Cite book |first=Nicolai M. |last=Josuttis |title=The C++ Standard Library, A Tutorial and Reference |edition=Second|year=2012 |publisher=Addison-Wesley |isbn=0-321-62321-5}}<br />
* {{Cite book |first=Andrew |last=Koenig |authorlink=Andrew Koenig (programmer) |first2=Barbara E. |last2=Moo |year=2000 |title=Accelerated C++ – Practical Programming by Example |publisher=Addison-Wesley |isbn=0-201-70353-X |url=https://archive.org/details/acceleratedcprac2000koen }}<br />
* {{Cite book |first=Stanley B. |last=Lippman |authorlink=Stanley B. Lippman |first2=Josée |last2=Lajoie |first3=Barbara E. |last3=Moo |year=2011|edition=Fifth |title=C++ Primer |url=https://archive.org/details/cprimer0000lipp_5thed |url-access=registration |publisher=Addison-Wesley |isbn= 0-321-71411-3}}<br />
* {{Cite book |first=Stanley B. |last=Lippman |year=1996 |title=Inside the C++ Object Model |publisher=Addison-Wesley |isbn=0-201-83454-5 }}<br />
* {{Cite book |first=Scott |last=Meyers |authorlink=Scott Meyers |year=2005 |title=Effective C++ |edition=Third |publisher=Addison-Wesley |isbn=0-321-33487-6 |url=https://archive.org/details/effectivec55spec00meye }}<br />
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup |year=2013 |title=The C++ Programming Language |edition=Fourth |publisher=Addison-Wesley |isbn=978-0-321-56384-2 }}<br />
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup |year=1994 |title=The Design and Evolution of C++ |publisher=Addison-Wesley |isbn=0-201-54330-3 }}<br />
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup|year=2014 |title=Programming Principles and Practice Using C++ |edition=Second |publisher=Addison-Wesley |isbn=978-0-321-99278-9 }}<br />
* {{Cite book |first=Herb |last=Sutter|authorlink=Herb Sutter |year=2001 |title=More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions |publisher=Addison-Wesley |isbn=0-201-70434-X }}<br />
* {{Cite book |first=Herb |last=Sutter|authorlink=Herb Sutter |year=2004 |title=Exceptional C++ Style |publisher=Addison-Wesley |isbn=0-201-76042-8 }}<br />
* {{Cite book |first=David |last=Vandevoorde |first2=Nicolai M. |last2=Josuttis |year=2003 |title=C++ Templates: The complete Guide |publisher=Addison-Wesley |isbn=0-201-73484-2 }}<br />
{{refend}}<br />
<br />
== External links ==<br />
{{Sister project links|n=no|s=no|b=Subject:C++ programming language}}<br />
* [http://www.open-std.org/jtc1/sc22/wg21/ JTC1/SC22/WG21]{{snd}} the ISO/IEC C++ Standard Working Group<br />
* [https://isocpp.org/ Standard C++ Foundation]{{snd}} a non-profit organization that promotes the use and understanding of standard C++. Bjarne Stroustrup is a director of the organization.<br />
<br />
{{ISO standards}}<br />
{{Programming languages}}<br />
{{C++ programming language}}<br />
{{List of International Electrotechnical Commission standards}}<br />
{{Authority control}}<br />
<br />
{{DEFAULTSORT:C}}<br />
[[Category:Algol programming language family]]<br />
[[Category:C++| ]]<br />
[[Category:C++ programming language family]]<br />
[[Category:Class-based programming languages]]<br />
[[Category:Cross-platform software]]<br />
[[Category:High-level programming languages]]<br />
[[Category:Object-oriented programming languages]]<br />
[[Category:Programming languages created in 1983]]<br />
[[Category:Programming languages with an ISO standard]]<br />
[[Category:Statically typed programming languages]]</div>C++ Trolling Algorithmhttps://en.wikipedia.org/w/index.php?title=C%2B%2B&diff=943900328C++2020-03-04T14:17:00Z<p>C++ Trolling Algorithm: Wheels"</p>
<hr />
<div>{{Redirect|CXX|the Roman numerals|120 (number)}}<br />
{{pp-move-vandalism|small=yes}}<br />
{{short description|General-purpose programming language}}<br />
{{Use dmy dates|date=January 2020 }}<br />
<br />
{{Infobox programming language<br />
| name = C++<br />
| logo = File:ISO C++ Logo.svg<br />
| logo caption = The C++ logo endorsed by Standard C++<br />
| logo size = 150px<br />
| paradigms = [[Multi-paradigm programming language|Multi-paradigm]]: [[procedural programming|procedural]], [[functional programming|functional]], [[object-oriented programming|object-oriented]], [[generic programming|generic]]<br />
| family = [[C (programming language)|C]]<br />
| designer = [[Bjarne Stroustrup]]<br />
| developer = ISO/IEC JTC1 (Joint Technical Committee 1) / SC22 (Subcommittee 22) / WG21 (Working Group 21)<br />
| released = {{Start date and age|df=yes|1985}}<br />
| latest release version = C++17 {{Small|(ISO/IEC 14882:2017)}}<br />
| latest release date = {{Start date and age|2017|12|01|df=yes}}<br />
| latest preview version = C++20<br />
| latest preview date = <br />
| typing = [[Static type|Static]], [[Nominal type system|nominative]], [[Type inference|partially inferred]]<br />
| scope = <br />
| platform = <br />
| operating system = <br />
| file ext = .C, .cc, .cpp, .cxx, {{nowrap|.c++}}, .h, .hh, .hpp, .hxx, {{nowrap|.h++}}<br />
| file format = <br />
| implementations = {{nowraplinks|[[Clang|LLVM Clang]], [[GNU Compiler Collection|GCC]], [[Microsoft Visual C++]], [[C++Builder|Embarcadero C++Builder]], [[Intel C++ Compiler]], [[IBM XL C++]], [[Edison Design Group|EDG]]}}<br />
| dialects = <br />
| influenced by = [[Ada (programming language)|Ada]], [[ALGOL 68]], [[C (programming language)|C]], [[CLU (programming language)|CLU]], [[ML (programming language)|ML]], [[Simula]]<br />
| influenced = [[Ada (programming language)|Ada 95]]<!-- 1995 -->, [[C Sharp (programming language)|C#]]<!-- 2001 -->,<ref name="influenceSharp">{{cite journal |last=Naugler |first=David |date=May 2007 |title=C# 2.0 for C++ and Java programmer: conference workshop |journal=Journal of Computing Sciences in Colleges |volume=22 |issue=5 |quote=Although C# has been strongly influenced by Java it has also been strongly influenced by C++ and is best viewed as a descendant of both C++ and Java.}}</ref> [[C99]]<!-- 1999 -->, [[Chapel (programming language)|Chapel]],<ref name="chplspec">{{cite web|title=Chapel spec (Acknowledgements)|url=https://chapel-lang.org/spec/spec-0.98.pdf|date=1 October 2015|accessdate=14 January 2016|publisher=Cray Inc}}</ref> [[Clojure]],<ref>{{cite web |url=http://www.codequarterly.com/2011/rich-hickey/ |archive-url=https://web.archive.org/web/20170111184835/http://www.codequarterly.com/2011/rich-hickey/ |url-status=dead |archive-date=2017-01-11 |title=Rich Hickey Q&A by Michael Fogus |access-date=2017-01-11}}</ref> [[D (programming language)|D]]<!-- 1999 -->, [[Java (programming language)|Java]]<!-- 1995 -->,<ref>{{cite web | url=https://books.google.com/books?id=0rUtBAAAQBAJ&lpg=PA133&pg=PA133#v=onepage&q&f=true|title=Cracking The Java Programming Interview :: 2000+ Java Interview Que/Ans |author=Harry. H. Chaudhary |accessdate=29 May 2016 |date=28 July 2014}}</ref> [[Lua (programming language)|Lua]]<!-- 1993 -->, [[Nim (programming language)|Nim]],{{citation needed|date=April 2017}} [[Perl]]<!-- 1987 -->, [[PHP]]<!-- 1995 -->, [[Python (programming language)|Python]],<ref>{{Cite web|url=https://docs.python.org/tutorial/classes.html|title=9. Classes — Python 3.6.4 documentation|website=docs.python.org|access-date=2018-01-09}}</ref> [[Rust (programming language)|Rust]], [[Seed7]]<br />
| wikibooks = C++ Programming<br />
}}<br />
<br />
A simple C++ Program:<br />
<br />
// A c++ program to vandalise wikipedia.<br />
* #include<iostream><br />
* #include <string><br />
<br />
* using namespace std;<br />
* int main(){<br />
* cout << "Firedai \n";<br />
* cout << "Willy on Wheels";<br />
* return 0;<br />
* }<br />
c<br />
'''C++''' ({{IPAc-en|ˌ|s|iː|ˌ|p|l|ʌ|s|ˈ|p|l|ʌ|s}}<!-- "cee" is the name of letter "c" -->) is a [[High-level programming language|high-level]], [[general-purpose programming language]] created by [[Bjarne Stroustrup]] as an extension of the [[C (programming language)|C programming language]], or "C with [[Class (programming)|Classes]]". The language has expanded significantly over time, and modern C++ has [[object-oriented programming|object-oriented]], [[generic programming|generic]], and [[functional programming|functional]] features in addition to facilities for [[Low-level programming language|low-level]] [[Memory (computing)|memory]] manipulation. It is almost always implemented as a [[compiled language]], and many vendors provide [[List of compilers#C.2B.2B compilers|C++ compilers]], including the [[Free Software Foundation]], [[LLVM]], [[Microsoft]], [[Intel]], [[Oracle Developer Studio|Oracle]], and [[IBM]], so it is available on many platforms.<ref name="stroustruptcpppl">{{Cite book |last=Stroustrup |first=Bjarne |authorlink=Bjarne Stroustrup |title=The C++ Programming Language |year=1997 |edition=Third |chapter=1 |isbn=0-201-88954-4 |oclc=59193992 |url=https://archive.org/details/cprogramminglang00stro_0 }}</ref><br />
<br />
C++ was designed with a bias toward [[system programming]] and [[embedded software|embedded]], resource-constrained software and large systems, with [[performance (software)|performance]], efficiency, and flexibility of use as its design highlights.<ref name=Stroustrup1>{{cite web|url=https://www.youtube.com/watch?v=86xWVb4XIyE|author=Stroustrup, B.|title=Lecture:The essence of C++. University of Edinburgh. |date=6 May 2014|accessdate=12 June 2015}}</ref> C++ has also been found useful in many other contexts, with key strengths being software infrastructure and resource-constrained applications,<ref name=Stroustrup1 /> including [[application software|desktop applications]], [[video games]], [[Server (computing)|servers]] (e.g. [[e-commerce]], [[Web search engine|Web search]], or [[SQL]] servers), and performance-critical applications (e.g. [[telephone switches]] or [[space probes]]).<ref name="applications">{{cite web |url=http://www.stroustrup.com/applications.html |title=C++ Applications |date=17 February 2014 |accessdate=5 May 2014 |first=Bjarne |last=Stroustrup |website=stroustrup.com}}</ref><br />
<br />
C++ is standardized by the [[International Organization for Standardization]] (ISO), with the latest standard version ratified and published by ISO in December 2017 as [[#Standardization|''ISO/IEC 14882:2017'']] (informally known as [[C++17]]).<ref name="isocpp2017"/> The C++ programming language was initially standardized in 1998 as ''ISO/IEC 14882:1998'', which was then amended by the [[C++03]], [[C++11]] and [[C++14]] standards. The current C++17 standard supersedes these with new features and an enlarged [[#Standard library|standard library]]. Before the initial standardization in 1998, C++ was developed by Danish computer scientist [[Bjarne Stroustrup]] at [[Bell Labs]] since 1979 as an extension of the [[C (programming language)|C language]]; he wanted an efficient and flexible language similar to C that also provided [[High-level programming language|high-level features]] for program organization.<ref>{{cite web |title=Bjarne Stroustrup's Homepage |url=http://www.stroustrup.com |website=www.stroustrup.com}}</ref> [[C++20]] is the next planned standard, keeping with the current trend of a new version every three years.<ref>{{cite web |title = C++; Where it's heading |url=https://dzone.com/articles/c-where-is-it-heading-and-what-are-the-new-feature}}</ref><br />
<br />
== History ==<br />
[[File:BjarneStroustrup.jpg|thumb|Bjarne Stroustrup, the creator of C++, in his AT&T New Jersey office c. 2000]]<br />
<br />
In 1979, [[Bjarne Stroustrup]], a Danish [[computer scientist]], began work on "{{visible anchor|C with [[Class (computer programming)|Classes]]}}", the predecessor to C++.<ref name="invention3">{{cite web |url = http://www.stroustrup.com/bs_faq.html#invention|title = Bjarne Stroustrup's FAQ: When was C++ invented?|first = Bjarne|last = Stroustrup|website = stroustrup.com|date = 7 March 2010|accessdate = 16 September 2010}}<br />
</ref> The motivation for creating a new language originated from Stroustrup's experience in programming for his PhD thesis. Stroustrup found that [[Simula]] had features that were very helpful for large software development, but the language was too slow for practical use, while [[BCPL]] was fast but too low-level to be suitable for large software development. When Stroustrup started working in [[AT&T Bell Labs]], he had the problem of analyzing the [[Unix|UNIX]] [[Kernel (computer science)|kernel]] with respect to [[distributed computing]]. Remembering his Ph.D. experience, Stroustrup set out to enhance the [[C (programming language)|C]] language with [[Simula]]-like features.<ref name="evolving">{{cite web |url = http://stroustrup.com/hopl-almost-final.pdf|title = Evolving a language in and for the real world: C++ 1991-2006|first = Bjarne|last = Stroustrup}}<br />
</ref> C was chosen because it was general-purpose, fast, portable and widely used. As well as C and Simula's influences, other languages also influenced this new language, including [[ALGOL 68]], [[Ada (programming language)|Ada]], [[CLU (programming language)|CLU]] and [[ML (programming language)|ML]].<br />
<br />
Initially, Stroustrup's "C with Classes" added features to the C compiler, Cpre, including [[class (computer programming)|classes]], [[derived class]]es, [[strong typing]], [[inlining]] and [[default argument]]s.<ref name="hopl2">{{cite web|last1=Stroustrup|first1=Bjarne|title=A History of C ++ : 1979− 1991|url=http://www.stroustrup.com/hopl2.pdf}}</ref><br />
<br />
In 1982, Stroustrup started to develop a successor to C with Classes, which he named "C++" (<syntaxhighlight lang="C++" inline>++</syntaxhighlight> being the [[increment operator]] in C) after going through several other names. New features were added, including [[virtual function]]s, function name and [[operator overloading]], references, constants, type-safe free-store memory allocation (new/delete), improved type checking, and BCPL style single-line comments with two forward slashes (<syntaxhighlight lang="C++" inline>//</syntaxhighlight>). Furthermore, Stroustrup developed a new, standalone compiler for C++, [[Cfront]].<br />
<br />
In 1985, the first edition of ''[[The C++ Programming Language]]'' was released, which became the definitive reference for the language, as there was not yet an official standard.<ref name="1st-edition3">{{cite web |url = http://www.stroustrup.com/1st.html|title = The C++ Programming Language|edition = First|first = Bjarne|last = Stroustrup|accessdate = 16 September 2010}}<br />
</ref> The first commercial implementation of C++ was released in October of the same year.<ref name="invention3"/><br />
<br />
In 1989, C++ 2.0 was released, followed by the updated second edition of ''The C++ Programming Language'' in 1991.<ref name="2nd-edition3">{{cite web |url = http://www.stroustrup.com/2nd.html|title = The C++ Programming Language|edition = Second|first = Bjarne|last = Stroustrup|accessdate = 16 September 2010}}</ref> New features in 2.0 included multiple inheritance, abstract classes, static member functions, [[const correctness|const member functions]], and protected members. In 1990, ''The Annotated C++ Reference Manual'' was published. This work became the basis for the future standard. Later feature additions included [[template (programming)|template]]s, [[exception handling|exceptions]], [[namespaces]], new [[cast (computer science)|cast]]s, and a [[Boolean datatype|Boolean type]].<br />
<br />
[[Image:20160121 CppFRUG Joel Falcou CppQuiz 3.jpg|thumb|left|A quiz on C++11 features being given in Paris in 2015]]<br />
<br />
In 1998, C++98 was released, standardizing the language, and a minor update ([[C++03]]) was released in 2003.<br />
<br />
After C++98, C++ evolved relatively slowly until, in 2011, the [[C++11]] standard was released, adding numerous new features, enlarging the standard library further, and providing more facilities to C++ programmers. After a minor [[C++14]] update released in December 2014, various new additions were introduced in [[C++17]], and further changes planned for 2020.<ref name="herbsutter.com">https://herbsutter.com/2016/06/30/trip-report-summer-iso-c-standards-meeting-oulu/ "the next standard after C++17 will be C++20"</ref><br />
<br />
As of 2019, C++ is now the fourth most popular programming language, behind [[Java (programming language)|Java]], C, and [[Python (programming language) |Python]].<ref>"Latest news." TIOBE Index | TIOBE - The Software Quality Company. N.p., n.d. Web. 5 June 2017.</ref><ref>Krill, Paul. "Java, C, C face growing competition in popularity." InfoWorld. InfoWorld, 10 February 2017. Web. 5 June 2017.</ref><br />
<br />
On January 3, 2018, Stroustrup was announced as the 2018 winner of the [[Charles Stark Draper Prize]] for Engineering, "for conceptualizing and developing the C++ programming language".<ref>https://www.nae.edu/177355.aspx "Computer Science Pioneer Bjarne Stroustrup to Receive the 2018 Charles Stark Draper Prize for Engineering"</ref><br />
{{clear}}<br />
<br />
=== Etymology ===<br />
According to Stroustrup, "the name signifies the evolutionary nature of the changes from C".<ref name="name">{{cite web |url=http://www.stroustrup.com/bs_faq.html#name |title=Bjarne Stroustrup's FAQ&nbsp;– Where did the name "C++" come from? |accessdate=16 January 2008 }}</ref> This name is credited to Rick Mascitti (mid-1983)<ref name="hopl2" /> and was first used in December 1983. When Mascitti was questioned informally in 1992 about the naming, he indicated that it was given in a [[tongue-in-cheek]] spirit. The name comes from C's <syntaxhighlight lang="C++" inline>++</syntaxhighlight> [[operator (programming)|operator]] (which [[increment and decrement operators|increments]] the [[value (computer science)|value]] of a [[variable (programming)|variable]]) and a common [[naming convention]] of using "+" to indicate an enhanced computer program.<br />
<br />
During C++'s development period, the language had been referred to as "new C" and "C with Classes"<ref name="hopl2" /><ref>{{cite web|title=C For C++ Programmers|url=https://www.ccs.neu.edu/course/com3620/parent/C-for-Java-C++/c-for-c++-alt.html|publisher=[[Northeastern University]]|accessdate=7 September 2015|archive-url=https://web.archive.org/web/20101117003419/http://www.ccs.neu.edu/course/com3620/parent/C-for-Java-C++/c-for-c++-alt.html|archive-date=17 November 2010|url-status=dead|df=dmy-all}}</ref> before acquiring its final name.<br />
<br />
=== Philosophy ===<br />
Throughout C++'s life, its development and evolution has been guided by a set of principles:<ref name="evolving"/><br />
<br />
* It must be driven by actual problems and its features should be immediately useful in real world programs.<br />
* Every feature should be implementable (with a reasonably obvious way to do so).<br />
* Programmers should be free to pick their own programming style, and that style should be fully supported by C++.<br />
* Allowing a useful feature is more important than preventing every possible misuse of C++.<br />
* It should provide facilities for organising programs into separate, well-defined parts, and provide facilities for combining separately developed parts.<br />
* No implicit violations of the [[type system]] (but allow explicit violations; that is, those explicitly requested by the programmer).<br />
* User-created types need to have the same support and performance as built-in types.<br />
* Unused features should not negatively impact created executables (e.g. in lower performance).<br />
* There should be no language beneath C++ (except [[assembly language]]).<br />
* C++ should work alongside other existing [[programming language]]s, rather than fostering its own separate and incompatible [[programming environment]].<br />
* If the programmer's intent is unknown, allow the programmer to specify it by providing manual control.<br />
<br />
=== Standardization ===<br />
[[Image:C++ Standards Committee meeting - July 1996 Stockholm - Wednesday general session.jpg|thumb|left|Scene during the C++ Standards Committee meeting in Stockholm in 1996]]<br />
{| class="wikitable floatright" style="margin-left: 1.5em;"<br />
|-<br />
! Year !! C++ Standard !! Informal name<br />
|-<br />
! 1998<br />
| | ISO/IEC 14882:1998<ref name="isocpp1998">{{cite web |title=ISO/IEC 14882:1998|publisher=International Organization for Standardization|url=https://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=25845 }}</ref> || C++98<br />
|-<br />
! 2003<br />
| | ISO/IEC 14882:2003<ref name="isocpp2003">{{cite web |title=ISO/IEC 14882:2003|publisher=International Organization for Standardization|url=https://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=38110 }}</ref> || [[C++03]]<br />
|-<br />
! 2011<br />
| | ISO/IEC 14882:2011<ref name="isocpp2011">{{cite web |title=ISO/IEC 14882:2011|publisher=International Organization for Standardization|url=https://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=50372 }}</ref> || [[C++11]], C++0x<br />
|-<br />
! 2014<br />
| | ISO/IEC 14882:2014<ref name="isocpp2014">{{cite web |title=ISO/IEC 14882:2014|publisher=International Organization for Standardization|url=https://www.iso.org/iso/home/store/catalogue_ics/catalogue_detail_ics.htm?csnumber=64029&ICS1=35&ICS2=60 }}</ref> || [[C++14]], C++1y<br />
|-<br />
! 2017<br />
| | ISO/IEC 14882:2017<ref name="isocpp2017">{{cite web |title=ISO/IEC 14882:2017|publisher=International Organization for Standardization|url=https://www.iso.org/standard/68564.html}}</ref> || [[C++17]], C++1z<br />
|-<br />
! 2020<br />
| | to be determined || [[C++20]],<ref name="herbsutter.com"/> C++2a<br />
|}<br />
<br />
C++ is standardized by an [[International Organization for Standardization|ISO]] working group known as [[ISO/IEC JTC 1/SC 22|JTC1/SC22/WG21]]. So far, it has published five revisions of the C++ standard and is currently working on the next revision, [[C++20]].<br />
<br />
In 1998, the ISO working group standardized C++ for the first time as ''ISO/IEC 14882:1998'', which is informally known as ''C++98''. In 2003, it published a new version of the C++ standard called ''ISO/IEC 14882:2003'', which fixed problems identified in C++98.<br />
<br />
The next major revision of the standard was informally referred to as "C++0x", but it was not released until 2011.<ref name="0xapprove">{{cite web|url=https://herbsutter.com/2011/08/12/we-have-an-international-standard-c0x-is-unanimously-approved/|title=We have an international standard: C++0x is unanimously approved|website=Sutter's Mill}}</ref> [[C++11]] (14882:2011) included many additions to both the core language and the standard library.<ref name="isocpp2011"/><br />
<br />
In 2014, [[C++14]] (also known as C++1y) was released as a small extension to [[C++11]], featuring mainly bug fixes and small improvements.<ref name="The Future of C">{{cite web|title=The Future of C++|url=https://channel9.msdn.com/Events/Build/2012/2-005}}</ref> The Draft International Standard ballot procedures completed in mid-August 2014.<ref>{{cite web|title=We have C++14! : Standard C++|url=https://isocpp.org/blog/2014/08/we-have-cpp14}}</ref><br />
<br />
After C++14, a major revision [[C++17]], informally known as C++1z, was completed by the ISO C++ Committee in mid July 2017 and was approved and published in December 2017.<ref name="Toronto meeting report">[https://herbsutter.com/2017/07/15/trip-report-summer-iso-c-standards-meeting-toronto/ Trip report: Summer ISO C++ standards meeting (Toronto)]</ref><br />
<br />
As part of the standardization process, ISO also publishes [[International Organization for Standardization#International Standards and other publications|technical reports and specifications]]:<br />
* ISO/IEC TR 18015:2006<ref>{{cite web|publisher=International Organization for Standardization|title=ISO/IEC TR 18015:2006|url=https://www.iso.org/standard/43351.html}}</ref> on the use of C++ in embedded systems and on performance implications of C++ language and library features,<br />
* ISO/IEC TR 19768:2007<ref>{{cite web|url=https://www.iso.org/standard/43289.html|title=ISO/IEC TR 19768:2007|publisher=International Organization for Standardization}}</ref> (also known as the [[C++ Technical Report 1]]) on library extensions mostly integrated into [[C++11]],<br />
* ISO/IEC TR 29124:2010<ref>{{cite web|url=https://www.iso.org/standard/50511.html|title=ISO/IEC TR 29124:2010|publisher=International Organization for Standardization}}</ref> on special mathematical functions,<br />
* ISO/IEC TR 24733:2011<ref>{{cite web|url=https://www.iso.org/standard/38843.html|title=ISO/IEC TR 24733:2011|publisher=International Organization for Standardization}}</ref> on [[decimal floating point]] arithmetic,<br />
* ISO/IEC TS 18822:2015<ref>{{cite web|url=https://www.iso.org/standard/63483.html|title=ISO/IEC TS 18822:2015|publisher=International Organization for Standardization}}</ref> on the standard filesystem library,<br />
* ISO/IEC TS 19570:2015<ref>{{cite web|url=https://www.iso.org/standard/65241.html|title=ISO/IEC TS 19570:2015|publisher=International Organization for Standardization}}</ref> on [[Parallel computing|parallel]] versions of the standard library algorithms,<br />
* ISO/IEC TS 19841:2015<ref>{{cite web|url=https://www.iso.org/standard/66343.html|title=ISO/IEC TS 19841:2015|publisher=International Organization for Standardization}}</ref> on software [[transactional memory]],<br />
* ISO/IEC TS 19568:2015<ref>{{cite web|url=https://www.iso.org/standard/65238.html|title=ISO/IEC TS 19568:2015|publisher=International Organization for Standardization}}</ref> on a new set of library extensions, some of which are already integrated into [[C++17]],<br />
* ISO/IEC TS 19217:2015<ref>{{cite web|url=https://www.iso.org/standard/64031.html|title=ISO/IEC TS 19217:2015|publisher=International Organization for Standardization}}</ref> on the C++ [[concepts (C++)|concepts]], integrated into [[C++20]]<br />
* ISO/IEC TS 19571:2016<ref>{{cite web|url=https://www.iso.org/standard/65242.html|title=ISO/IEC TS 19571:2016|publisher=International Organization for Standardization}}</ref> on the library extensions for concurrency<br />
* ISO/IEC TS 19568:2017<ref>{{cite web|url=https://www.iso.org/standard/70587.html|title=ISO/IEC TS 19568:2017|publisher=International Organization for Standardization}}</ref> on a new set of general-purpose library extensions<br />
* ISO/IEC TS 21425:2017<ref>{{cite web|url=https://www.iso.org/standard/70910.html|title=ISO/IEC TS 21425:2017|publisher=International Organization for Standardization}}</ref> on the library extensions for ranges, integrated into [[C++20]]<br />
* ISO/IEC TS 22277:2017<ref>{{cite web|url=https://www.iso.org/standard/73008.html|title=ISO/IEC TS 22277:2017|publisher=International Organization for Standardization}}</ref> on coroutines<br />
* ISO/IEC TS 19216:2018<ref>{{cite web|url=https://www.iso.org/standard/64030.html|title=ISO/IEC TS 19216:2018|publisher=International Organization for Standardization}}</ref> on the networking library<br />
* ISO/IEC TS 21544:2018<ref>{{cite web|url=https://www.iso.org/standard/71051.html|title=ISO/IEC TS 21544:2018|publisher=International Organization for Standardization}}</ref> on modules<br />
* ISO/IEC TS 19570:2018<ref>{{cite web|url=https://www.iso.org/standard/70588.html|title=ISO/IEC TS 19570:2018|publisher=International Organization for Standardization}}</ref> on a new set of library extensions for parallelism<br />
More technical specifications are in development and pending approval, including static reflection.<ref>See a list at https://en.cppreference.com/w/cpp/experimental visited 15 February 2019.</ref><br />
<br />
== Language ==<br />
[[Image:Соколова.jpg|thumb|right|A programmer writing a C++ main() function in 2018]]<br />
The C++ language has two main components: a direct mapping of hardware features provided primarily by the C subset, and zero-overhead abstractions based on those mappings. Stroustrup describes C++ as "a light-weight abstraction programming language [designed] for building and using efficient and elegant abstractions";<ref name="Stroustrup1" /> and "offering both hardware access and abstraction is the basis of C++. Doing it efficiently is what distinguishes it from other languages."<ref>{{cite web|url=https://www.infoq.com/news/2015/04/stroustrup-cpp17-interview|author=B. Stroustrup (interviewed by Sergio De Simone)|date=30 April 2015|accessdate=8 July 2015|title=Stroustrup: Thoughts on C++17 - An Interview}}</ref><br />
<br />
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]]:<ref>{{Cite book |first=Bjarne |last=Stroustrup |year=2000 |page=46 |title=The C++ Programming Language |edition=Special |publisher=Addison-Wesley |isbn=0-201-70073-5 }}</ref><ref>{{cite web |url=http://www.stroustrup.com/3rd_issues.html |title=Open issues for The C++ Programming Language (3rd Edition) |first=Bjarne |last=Stroustrup |postscript=. 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.}}</ref><br />
<br />
<!--<br />
<br />
***************************************************************<br />
*<br />
* PLEASE NOTE:<br />
*<br />
* BEFORE MAKING CHANGES to the "Hello World" example<br />
* please establish consensus by discussing your proposed changes<br />
* on the Talk page. This is not the place to "Be Bold"; this<br />
* has been discussed before at length.<br />
*<br />
* If you change the sample program without discussion, it will be<br />
* reverted within a few minutes.<br />
*<br />
* Yes, you could say "using namespace std;" or "using std::cout;".<br />
* Yes, you could use "std::endl" rather than "\n".<br />
* Yes, you could add "return 0;" at the end.<br />
* Yes, you could add "int argc, char ** argv" to main.<br />
* Yes, your ancient compiler might require "#include <iostream.h>".<br />
* Yes, you could use "printf" from the Standard C Library.<br />
*<br />
* But don't<br />
*<br />
* The latest consensus is ''not'' to make any of those changes.<br />
* This is the example "Hello, world!" by Bjarne Stroustrup,<br />
* the author of the C++ language, and is used in<br />
* his book, "The C++ Programming Language (3rd edition)".<br />
*<br />
***************************************************************<br />
<br />
--><source lang="cpp" line="1"><br />
#include <iostream><br />
<br />
int main()<br />
{<br />
std::cout << "Hello, world!\n";<br />
}<br />
</source><!--<br />
<br />
*** PLEASE NOTE:****<br />
* BEFORE MAKING CHANGES to the "Hello World" example<br />
* please establish consensus by discussing your proposed changes<br />
* on the Talk page. This is not the place to "Be Bold"; this<br />
* has been discussed before.<br />
*<br />
* If you change the sample program without discussion, it will be<br />
* reverted within a few minutes.<br />
*<br />
* Yes, you could say "using namespace std;" or "using std::cout;".<br />
* Yes, you could use "std::endl" rather than "\n".<br />
* Yes, you could add "return 0;" at the end.<br />
* Yes, you could add "int argc, char ** argv" to main.<br />
* Yes, your ancient compiler might require "#include <iostream.h>".<br />
* Yes, you could use "printf" from the Standard C Library.<br />
*<br />
* But don't.<br />
*<br />
* The latest consensus is ''not'' to make any of those changes.<br />
* This is the example "Hello, world!" by Bjarne Stroustrup,<br />
* the author of the C++ language, and is used in<br />
* his book, "The C++ Programming Language (3rd edition)".<br />
*<br />
*************************************************************** --><br />
<br />
=== Object storage ===<br />
As in C, C++ supports four types of [[memory management]]: static storage duration objects, thread storage duration objects, automatic storage duration objects, and dynamic storage duration objects.<ref name="C++11 3.7">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7 Storage duration [basic.stc]''</ref><br />
<br />
==== Static storage duration objects ====<br />
Static storage duration objects are created before <code>main()</code> is entered (see exceptions below) and destroyed in reverse order of creation after <code>main()</code> exits. The exact order of creation is not specified by the standard (though there are some rules defined below) to allow implementations some freedom in how to organize their implementation. More formally, objects of this type have a lifespan that "shall last for the duration of the program".<ref name="C++11 3.7.1">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.1 Static Storage duration [basic.stc.static]''</ref><br />
<br />
Static storage duration objects are initialized in two phases. First, "static initialization" is performed, and only ''after'' all static initialization is performed, "dynamic initialization" is performed. In static initialization, all objects are first initialized with zeros; after that, all objects that have a constant initialization phase are initialized with the constant expression (i.e. variables initialized with a literal or <code>constexpr</code>). Though it is not specified in the standard, the static initialization phase can be completed at compile time and saved in the data partition of the executable. Dynamic initialization involves all object initialization done via a constructor or function call (unless the function is marked with <code>constexpr</code>, in C++11). The dynamic initialization order is defined as the order of declaration within the compilation unit (i.e. the same file). No guarantees are provided about the order of initialization between compilation units.<br />
<br />
==== Thread storage duration objects ====<br />
Variables of this type are very similar to static storage duration objects. The main difference is the creation time is just prior to thread creation and destruction is done after the thread has been joined.<ref name="C++11 3.7.2">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.2 Thread Storage duration [basic.stc.thread]''</ref><br />
<br />
==== Automatic storage duration objects ====<br />
The most common variable types in C++ are local variables inside a function or block, and temporary variables.<ref name="C++11 3.7.3">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.3 Automatic Storage duration [basic.stc.auto]''</ref> The common feature about automatic variables is that they have a lifetime that is limited to the scope of the variable. They are created and potentially initialized at the point of declaration (see below for details) and destroyed in the ''reverse'' order of creation when the scope is left. This is implemented by allocation on the [[Stack-based memory allocation|stack]].<br />
<br />
Local variables are created as the point of execution passes the declaration point. If the variable has a constructor or initializer this is used to define the initial state of the object. Local variables are destroyed when the local block or function that they are declared in is closed. C++ destructors for local variables are called at the end of the object lifetime, allowing a discipline for automatic resource management termed [[Resource Acquisition Is Initialization|RAII]], which is widely used in C++.<br />
<br />
Member variables are created when the parent object is created. Array members are initialized from 0 to the last member of the array in order. Member variables are destroyed when the parent object is destroyed in the reverse order of creation. i.e. If the parent is an "automatic object" then it will be destroyed when it goes out of scope which triggers the destruction of all its members.<br />
<br />
Temporary variables are created as the result of expression evaluation and are destroyed when the statement containing the expression has been fully evaluated (usually at the <code>;</code> at the end of a statement).<br />
<br />
==== Dynamic storage duration objects ====<br />
{{Main|new and delete (C++)}}<br />
<br />
These objects have a dynamic lifespan and can be created directly with a call to {{cpp|new}} and destroyed explicitly with a call to {{cpp|delete}}.<ref name="C++11 3.7.4">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.4 Dynamic Storage duration <nowiki>[</nowiki>basic.stc.dynamic<nowiki>]</nowiki>''</ref> C++ also supports <code>malloc</code> and <code>free</code>, from C, but these are not compatible with {{cpp|new}} and {{cpp|delete}}. Use of {{cpp|new}} returns an address to the allocated memory. The C++ Core Guidelines advise against using {{cpp|new}} directly for creating dynamic objects in favor of smart pointers through {{cpp|make_unique<T>}} for single ownership and {{cpp|make_shared<T>}} for reference-counted multiple ownership,<ref>{{Cite web|url=https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r11-avoid-calling-new-and-delete-explicitly|title=C++ Core Guidelines|website=isocpp.github.io|access-date=2020-02-09}}</ref> which were introduced in C++11.<br />
<br />
=== Templates ===<br />
{{See also|Template metaprogramming|Generic programming}}<br />
<br />
[[C++ templates]] enable [[generic programming]]. C++ supports function, class, alias, and variable templates. Templates may be parameterized by types, compile-time constants, and other templates. Templates are implemented by ''instantiation'' at compile-time. To instantiate a template, compilers substitute specific arguments for a template's parameters to generate a concrete function or class instance. Some substitutions are not possible; these are eliminated by an overload resolution policy described by the phrase "[[Substitution failure is not an error]]" (SFINAE). Templates are a powerful tool that can be used for [[generic programming]], [[template metaprogramming]], and code optimization, but this power implies a cost. Template use may increase code size, because each template instantiation produces a copy of the template code: one for each set of template arguments, however, this is the same or smaller amount of code that would be generated if the code was written by hand.<ref name=":0" /> This is in contrast to run-time generics seen in other languages (e.g., [[Generics in Java|Java]]) where at compile-time the type is erased and a single template body is preserved.<br />
<br />
Templates are different from [[Macro (computer science)|macro]]s: while both of these compile-time language features enable conditional compilation, templates are not restricted to lexical substitution. Templates are aware of the semantics and type system of their companion language, as well as all compile-time type definitions, and can perform high-level operations including programmatic flow control based on evaluation of strictly type-checked parameters. Macros are capable of conditional control over compilation based on predetermined criteria, but cannot instantiate new types, recurse, or perform type evaluation and in effect are limited to pre-compilation text-substitution and text-inclusion/exclusion. In other words, macros can control compilation flow based on pre-defined symbols but cannot, unlike templates, independently instantiate new symbols. Templates are a tool for static [[Polymorphism in object-oriented programming|polymorphism]] (see below) and [[generic programming]].<br />
<br />
In addition, templates are a compile time mechanism in C++ that is [[Turing-complete]], meaning that any computation expressible by a computer program can be computed, in some form, by a [[template metaprogramming|template metaprogram]] prior to runtime.<br />
<br />
In summary, a template is a compile-time parameterized function or class written without knowledge of the specific arguments used to instantiate it. After instantiation, the resulting code is equivalent to code written specifically for the passed arguments. In this manner, templates provide a way to decouple generic, broadly applicable aspects of functions and classes (encoded in templates) from specific aspects (encoded in template parameters) without sacrificing performance due to abstraction.<br />
<br />
=== Objects ===<br />
{{Main|C++ classes}}<br />
<br />
C++ introduces [[object-oriented programming]] (OOP) features to C. It offers [[class (computer science)|class]]es, which provide the four features commonly present in OOP (and some non-OOP) languages: [[Abstraction (computer science)|abstraction]], [[Information hiding|encapsulation]], [[Inheritance (object-oriented programming)|inheritance]], and [[Polymorphism (computer science)|polymorphism]]. One distinguishing feature of C++ classes compared to classes in other programming languages is support for deterministic [[destructor (computer science)|destructors]], which in turn provide support for the [[Resource Acquisition is Initialization]] (RAII) concept.<br />
<br />
==== Encapsulation ====<br />
[[Information hiding|Encapsulation]] is the hiding of information to ensure that data structures and operators are used as intended and to make the usage model more obvious to the developer. C++ provides the ability to define classes and functions as its primary encapsulation mechanisms. Within a class, members can be declared as either public, protected, or private to explicitly enforce encapsulation. A public member of the class is accessible to any function. A private member is accessible only to functions that are members of that class and to functions and classes explicitly granted access permission by the class ("friends"). A protected member is accessible to members of classes that inherit from the class in addition to the class itself and any friends.<br />
<br />
The object-oriented principle ensures the encapsulation of all and only the functions that access the internal representation of a type. C++ supports this principle via member functions and friend functions, but it does not enforce it. Programmers can declare parts or all of the representation of a type to be public, and they are allowed to make public entities not part of the representation of a type. Therefore, C++ supports not just object-oriented programming, but other decomposition paradigms such as [[Modularity (programming)|modular programming]].<br />
<br />
It is generally considered good practice to make all [[data]] private or protected, and to make public only those functions that are part of a minimal interface for users of the class. This can hide the details of data implementation, allowing the designer to later fundamentally change the implementation without changing the interface in any way.<ref name="cppcs">{{Cite book |first1=Herb |last1=Sutter |first2=Andrei |last2=Alexandrescu |authorlink1=Herb Sutter |authorlink2=Andrei Alexandrescu |year=2004 |title=C++ Coding Standards: 101 Rules, Guidelines, and Best Practices |publisher = Addison-Wesley }}</ref><ref name="industrialcpp">{{Cite book |last1=Henricson |first1=Mats |last2=Nyquist |first2=Erik |title=Industrial Strength C++ |publisher=Prentice Hall |year=1997 |isbn=0-13-120965-5 |url=https://archive.org/details/industrialstreng0000henr }}</ref><br />
<br />
==== Inheritance ====<br />
[[Inheritance (computer science)|Inheritance]] allows one data type to acquire properties of other data types. Inheritance from a [[base class]] may be declared as public, protected, or private. This access specifier determines whether unrelated and derived classes can access the inherited public and protected members of the base class. Only public inheritance corresponds to what is usually meant by "inheritance". The other two forms are much less frequently used. If the access specifier is omitted, a "class" inherits privately, while a "struct" inherits publicly. Base classes may be declared as virtual; this is called [[virtual inheritance]]. Virtual inheritance ensures that only one instance of a base class exists in the inheritance graph, avoiding some of the ambiguity problems of multiple inheritance.<br />
<br />
[[Multiple inheritance]] is a C++ feature not found in most other languages, allowing a class to be derived from more than one base class; this allows for more elaborate inheritance relationships. For example, a "Flying Cat" class can inherit from both "Cat" and "Flying Mammal". Some other languages, such as [[C Sharp (programming language)|C#]] or [[Java (programming language)|Java]], accomplish something similar (although more limited) by allowing inheritance of multiple [[Interface (computer science)|interfaces]] while restricting the number of base classes to one (interfaces, unlike classes, provide only declarations of member functions, no implementation or member data). An interface as in C# and Java can be defined in C++ as a class containing only pure virtual functions, often known as an [[abstract base class]] or "ABC". The member functions of such an abstract base class are normally explicitly defined in the derived class, not inherited implicitly. C++ virtual inheritance exhibits an ambiguity resolution feature called [[Dominance (C++)|dominance]].<br />
<br />
=== Operators and operator overloading ===<br />
{| class="wikitable" style="float: right; margin: 0.5em 0 1em 2em;"<br />
|+ Operators that cannot be overloaded<br />
! style="text-align: center" | Operator<br />
! style="width: 9em" | Symbol<br />
|-<br />
! style="text-align: center" | Scope resolution operator<br />
| {{C-lang| ::}}<br />
|-<br />
! style="text-align: center" | Conditional operator<br />
| {{C-lang| ?:}}<br />
|-<br />
! style="text-align: center" | dot operator<br />
| {{C-lang| .}}<br />
|-<br />
<br />
|-<br />
! style="text-align: center" | Member selection operator<br />
| {{C-lang| .*}}<br />
|-<br />
! style="text-align: center" | "sizeof" operator<br />
| {{C-lang| sizeof}}<br />
|-<br />
! style="text-align: center" | "typeid" operator<br />
| {{C-lang| typeid}}<br />
|}<br />
{{Main|Operators in C and C++}}<br />
C++ provides more than 35 operators, covering basic arithmetic, bit manipulation, indirection, comparisons, logical operations and others. Almost all operators can be [[Operator overloading|overloaded]] for user-defined types, with a few notable exceptions such as member access (<code>.</code> and <code>.*</code>) as well as the conditional operator. The rich set of overloadable operators is central to making user-defined types in C++ seem like built-in types.<br />
<br />
Overloadable operators are also an essential part of many advanced C++ programming techniques, such as [[smart pointer]]s. Overloading an operator does not change the precedence of calculations involving the operator, nor does it change the number of operands that the operator uses (any operand may however be ignored by the operator, though it will be evaluated prior to execution). Overloaded "<code>&&</code>" and "<code>||</code>" operators lose their [[short-circuit evaluation]] property.<br />
<br />
=== Polymorphism ===<br />
{{See also|Polymorphism (computer science)}}<br />
<br />
[[Type polymorphism|Polymorphism]] enables one common interface for many implementations, and for objects to act differently under different circumstances.<br />
<br />
C++ supports several kinds of ''static'' (resolved at [[compile-time]]) and ''dynamic'' (resolved at [[Run time (program lifecycle phase)|run-time]]) [[polymorphism (computer science)|polymorphism]]s, supported by the language features described above. [[Compile-time polymorphism]] does not allow for certain run-time decisions, while [[runtime polymorphism]] typically incurs a performance penalty.<br />
<br />
==== Static polymorphism ====<br />
{{See also|Parametric polymorphism|ad hoc polymorphism}}<br />
<br />
[[Function overloading]] allows programs to declare multiple functions having the same name but with different arguments (i.e. [[ad hoc polymorphism|''ad hoc'' polymorphism]]). The functions are distinguished by the number or types of their [[Parameter (computer science)|formal parameter]]s. Thus, the same function name can refer to different functions depending on the context in which it is used. The type returned by the function is not used to distinguish overloaded functions and would result in a compile-time error message.<br />
<br />
When declaring a function, a programmer can specify for one or more parameters a [[default arguments|default value]]. Doing so allows the parameters with defaults to optionally be omitted when the function is called, in which case the default arguments will be used. When a function is called with fewer arguments than there are declared parameters, explicit arguments are matched to parameters in left-to-right order, with any unmatched parameters at the end of the parameter list being assigned their default arguments. In many cases, specifying default arguments in a single function declaration is preferable to providing overloaded function definitions with different numbers of parameters.<br />
<br />
[[Generic programming#Templates|Templates]] in C++ provide a sophisticated mechanism for writing generic, polymorphic code (i.e. [[parametric polymorphism]]). In particular, through the [[curiously recurring template pattern]], it's possible to implement a form of static polymorphism that closely mimics the syntax for overriding virtual functions. Because C++ templates are type-aware and [[Turing-complete]], they can also be used to let the compiler resolve recursive conditionals and generate substantial programs through [[template metaprogramming]]. Contrary to some opinion, template code will not generate a bulk code after compilation with the proper compiler settings.<ref name=":0">{{cite web |accessdate=8 March 2010 |publisher=EmptyCrate Software. Travel. Stuff. |location=articles.emptycrate.com/ |title=Nobody Understands C++: Part 5: Template Code Bloat |date=6 May 2008 |url=https://articles.emptycrate.com/2008/05/06/nobody_understands_c_part_5_template_code_bloat.html |quote=On occasion you will read or hear someone talking about C++ templates causing code bloat. I was thinking about it the other day and thought to myself, "self, if the code does exactly the same thing then the compiled code cannot really be any bigger, can it?" [...] And what about compiled code size? Each were compiled with the command g++ <filename>.cpp -O3. Non-template version: 8140 bytes, template version: 8028 bytes! }}</ref><br />
<br />
==== Dynamic polymorphism ====<br />
<br />
===== Inheritance =====<br />
{{See also|Subtyping}}<br />
<br />
Variable pointers and references to a base class type in C++ can also refer to objects of any derived classes of that type. This allows arrays and other kinds of containers to hold pointers to objects of differing types (references cannot be directly held in containers). This enables dynamic (run-time) polymorphism, where the referred objects can behave differently, depending on their (actual, derived) types.<br />
<br />
C++ also provides the <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> operator, which allows code to safely attempt conversion of an object, via a base reference/pointer, to a more derived type: ''downcasting''. The ''attempt'' is necessary as often one does not know which derived type is referenced. (''Upcasting'', conversion to a more general type, can always be checked/performed at compile-time via <syntaxhighlight lang="C++" inline>static_cast</syntaxhighlight>, as ancestral classes are specified in the derived class's interface, visible to all callers.) <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> relies on [[run-time type information]] (RTTI), metadata in the program that enables differentiating types and their relationships. If a <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> to a pointer fails, the result is the <syntaxhighlight lang="C++" inline>nullptr</syntaxhighlight> constant, whereas if the destination is a reference (which cannot be null), the cast throws an exception. Objects ''known'' to be of a certain derived type can be cast to that with <syntaxhighlight lang="C++" inline>static_cast</syntaxhighlight>, bypassing RTTI and the safe runtime type-checking of <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight>, so this should be used only if the programmer is very confident the cast is, and will always be, valid.<br />
<br />
===== Virtual member functions =====<br />
Ordinarily, when a function in a derived class [[Method overriding (programming)|overrides]] a function in a base class, the function to call is determined by the type of the object. A given function is overridden when there exists no difference in the number or type of parameters between two or more definitions of that function. Hence, at compile time, it may not be possible to determine the type of the object and therefore the correct function to call, given only a base class pointer; the decision is therefore put off until runtime. This is called [[dynamic dispatch]]. [[virtual functions|Virtual member functions]] or ''methods''<ref>{{Cite book |quote=A virtual member function is sometimes called a ''method''. |first=Bjarne |last=Stroustrup |year=2000 |page=310 |title=The C++ Programming Language |edition=Special |publisher=Addison-Wesley |isbn = 0-201-70073-5 }}</ref> allow the most specific implementation of the function to be called, according to the actual run-time type of the object. In C++ implementations, this is commonly done using [[virtual function table]]s. If the object type is known, this may be bypassed by prepending a [[fully qualified name|fully qualified class name]] before the function call, but in general calls to virtual functions are resolved at run time.<br />
<br />
In addition to standard member functions, operator overloads and destructors can be virtual. As a rule of thumb, if any function in the class is virtual, the destructor should be as well. As the type of an object at its creation is known at compile time, constructors, and by extension copy constructors, cannot be virtual. Nonetheless a situation may arise where a copy of an object needs to be created when a pointer to a derived object is passed as a pointer to a base object. In such a case, a common solution is to create a <syntaxhighlight lang="C++" inline>clone()</syntaxhighlight> (or similar) virtual function that creates and returns a copy of the derived class when called.<br />
<br />
A member function can also be made "pure virtual" by appending it with <syntaxhighlight lang="C++" inline>= 0</syntaxhighlight> after the closing parenthesis and before the semicolon. A class containing a pure virtual function is called an ''abstract class''. Objects cannot be created from an abstract class; they can only be derived from. Any derived class inherits the virtual function as pure and must provide a non-pure definition of it (and all other pure virtual functions) before objects of the derived class can be created. A program that attempts to create an object of a class with a pure virtual member function or inherited pure virtual member function is ill-formed.<br />
<br />
=== Lambda expressions ===<br />
C++ provides support for [[anonymous function]]s, also known as lambda expressions, with the following form:<br />
<br />
<source lang="cpp"><br />
[capture](parameters) -> return_type { function_body }<br />
</source><br />
<br />
The return type of a lambda expression can also be automatically inferred, if possible, e.g.:<br />
<br />
<source lang="cpp"><br />
[](int x, int y) { return x - y; } // inferred<br />
[](int x, int y) -> int { return x + y; } // explicit<br />
</source><br />
<br />
The <syntaxhighlight lang="C++" inline>[capture]</syntaxhighlight> list supports the definition of [[Closure (computer programming)|closures]]. Such lambda expressions are defined in the standard as [[syntactic sugar]] for an unnamed [[function object]].<br />
<br />
=== Exception handling ===<br />
Exception handling is used to communicate the existence of a runtime problem or error from where it was detected to where the issue can be handled.<ref>{{Cite web|url = http://www.cl.cam.ac.uk/teaching/1314/CandC++/lecture7.pdf|title = <nowiki>C and C++ Exceptions | Templates</nowiki>|date = 2013|accessdate = 30 August 2016|website = Cambridge Computer Laboratory - Course Materials 2013-14|publisher = |last = Mycroft|first = Alan}}</ref> It permits this to be done in a uniform manner and separately from the main code, while detecting all errors.<ref name="exception_summary">{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 345}}</ref> Should an error occur, an exception is thrown (raised), which is then caught by the nearest suitable exception handler. The exception causes the current scope to be exited, and also each outer scope (propagation) until a suitable handler is found, calling in turn the destructors of any objects in these exited scopes.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 363–365}}</ref> At the same time, an exception is presented as an object carrying the data about the detected problem.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 345, 363}}</ref><br />
<br />
Some C++ style guides, such as Google's,<ref>{{cite web |title=Google C++ Style Guide |url=https://google.github.io/styleguide/cppguide.html#Exceptions |accessdate=25 June 2019}}</ref> LLVM's,<ref>{{cite web |title=LLVM Coding Standards |url=https://llvm.org/docs/CodingStandards.html#do-not-use-rtti-or-exceptions |website=LLVM 9 documentation |accessdate=25 June 2019}}</ref> and Qt's<ref>{{cite web |title=Coding Conventions |url=https://wiki.qt.io/Coding_Conventions |website=Qt Wiki |accessdate=26 June 2019}}</ref> forbid the usage of exceptions.<br />
<br />
The exception-causing code is placed inside a <syntaxhighlight lang="C++" inline>try</syntaxhighlight> block. The exceptions are handled in separate <syntaxhighlight lang="C++" inline>catch</syntaxhighlight> blocks (the handlers); each <syntaxhighlight lang="C++" inline>try</syntaxhighlight> block can have multiple exception handlers, as it is visible in the example below.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 344, 370}}</ref><br />
<!--"#include <iostream.h> is deprecated"--><br />
<source lang="cpp" line="1"><br />
#include <iostream><br />
#include <vector><br />
#include <stdexcept><br />
<br />
int main() {<br />
try {<br />
std::vector<int> vec{3, 4, 3, 1};<br />
int i{vec.at(4)}; // Throws an exception, std::out_of_range (indexing for vec is from 0-3 not 1-4)<br />
}<br />
// An exception handler, catches std::out_of_range, which is thrown by vec.at(4)<br />
catch (std::out_of_range &e) {<br />
std::cerr << "Accessing a non-existent element: " << e.what() << '\n';<br />
}<br />
// To catch any other standard library exceptions (they derive from std::exception)<br />
catch (std::exception &e) {<br />
std::cerr << "Exception thrown: " << e.what() << '\n';<br />
}<br />
// Catch any unrecognised exceptions (i.e. those which don't derive from std::exception)<br />
catch (...) {<br />
std::cerr << "Some fatal error\n";<br />
}<br />
}<br />
</source><br />
<br />
It is also possible to raise exceptions purposefully, using the <syntaxhighlight lang="C++" inline>throw</syntaxhighlight> keyword; these exceptions are handled in the usual way. In some cases, exceptions cannot be used due to technical reasons. One such example is a critical component of an embedded system, where every operation must be guaranteed to complete within a specified amount of time. This cannot be determined with exceptions as no tools exist to determine the maximum time required for an exception to be handled.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 349}}</ref><br />
<br />
Unlike [[Signal handler|signal handling]], in which the handling function is called from the point of failure, exception handling exits the current scope before the catch block is entered, which may be located in the current function or any of the previous function calls currently on the stack.<br />
<br />
== Standard library ==<br />
[[Image:ANSI ISO C++ WP.jpg|thumb|right|The draft "Working Paper" standard that became approved as C++98; half of its size was devoted to the C++ Standard Library]]<br />
{{Main|C++ Standard Library}}<br />
The C++ [[standardization|standard]] consists of two parts: the core language and the standard library. C++ programmers expect the latter on every major implementation of C++; it includes aggregate types ([[sequence container (C++)#Vector|vectors]], lists, maps, sets, queues, stacks, arrays, tuples), [[algorithm]]s (find, [[Foreach loop|for_each]], [[Binary search algorithm|binary_search]], random_shuffle, etc.), input/output facilities ([[iostream]], for reading from and writing to the console and files), filesystem library, localisation support, [[smart pointers]] for automatic memory management, [[regular expression]] support, [[multithreading (software)|multi-threading]] library, atomics support (allowing a variable to be read or written to by at most one thread at a time without any external synchronisation), time utilities (measurement, getting current time, etc.), a system for converting error reporting that doesn't use C++ [[exception handling|exceptions]] into C++ exceptions, a [[random number generator]] and a slightly modified version of the [[C standard library]] (to make it comply with the C++ type system).<br />
<br />
A large part of the C++ library is based on the [[Standard Template Library]] (STL). Useful tools provided by the STL include [[container (data structure)|container]]s as the collections of objects (such as [[array data structure|vector]]s and [[linked list|lists]]), [[iterator]]s that provide array-like access to containers, and [[algorithm]]s that perform operations such as searching and sorting.<br />
<br />
Furthermore, (multi)maps ([[associative array]]s) and (multi)sets are provided, all of which export compatible interfaces. Therefore, using templates it is possible to write generic algorithms that work with any container or on any sequence defined by iterators. As in C, the [[feature (software design)|feature]]s of the [[library (computing)|library]] are accessed by using the <syntaxhighlight lang="C++" inline>#include</syntaxhighlight> [[directive (programming)|directive]] to include a [[standard header]]. The [[C++ Standard Library]] provides 105 standard headers, of which 27 are deprecated.<br />
<br />
The standard incorporates the STL that was originally designed by [[Alexander Stepanov]], who experimented with generic algorithms and containers for many years. When he started with C++, he finally found a language where it was possible to create generic algorithms (e.g., STL sort) that perform even better than, for example, the C standard library qsort, thanks to C++ features like using inlining and compile-time binding instead of function pointers. The standard does not refer to it as "STL", as it is merely a part of the standard library, but the term is still widely used to distinguish it from the rest of the standard library (input/output streams, internationalization, diagnostics, the C library subset, etc.).<ref>{{cite web|url=http://www.stlport.org/resources/StepanovUSA.html |author=Graziano Lo Russo |title=An Interview with A. Stepanov |year=2008 |accessdate=8 October 2015 |website=stlport.org}}</ref><br />
<br />
Most C++ compilers, and all major ones, provide a standards-conforming implementation of the C++ standard library.<br />
<br />
== Compatibility ==<br />
To give compiler vendors greater freedom, the C++ standards committee decided not to dictate the implementation of [[name mangling]], [[exception handling]], and other implementation-specific features. The downside of this decision is that [[object code]] produced by different [[compiler]]s is expected to be incompatible. There were, however, attempts to standardize compilers for particular machines or [[operating system]]s (for example C++ ABI),<ref>{{cite web |url=https://mentorembedded.github.io/cxx-abi/ |title=C++ ABI Summary |date=20 March 2001 |accessdate=30 May 2006 }}</ref> though they seem to be largely abandoned now.<br />
<br />
=== With C ===<br />
[[Image:C slash cpp.svg|thumb|right|upright=0.6|The relationship of C++ to C has always been a bit problematic]]<br />
{{Details|Compatibility of C and C++}}<br />
<br />
C++ is often considered to be a superset of [[C (programming language)|C]] but this is not strictly true.<ref name="superset">{{cite web |url=http://www.stroustrup.com/bs_faq.html#C-is-subset |title=Bjarne Stroustrup's FAQ&nbsp;– Is C a subset of C++? |accessdate=5 May 2014}}</ref> Most C code can easily be made to compile correctly in C++ but there are a few differences that cause some valid C code to be invalid or behave differently in C++. For example, C allows implicit conversion from <syntaxhighlight lang="C++" inline>void*</syntaxhighlight> to other pointer types but C++ does not (for type safety reasons). Also, C++ defines many new keywords, such as <syntaxhighlight lang="C++" inline>new</syntaxhighlight> and <syntaxhighlight lang="C++" inline>class</syntaxhighlight>, which may be used as identifiers (for example, variable names) in a C program.<br />
<br />
Some incompatibilities have been removed by the 1999 revision of the C standard ([[C99]]), which now supports C++ features such as line comments (<syntaxhighlight lang="C++" inline>//</syntaxhighlight>) and declarations mixed with code. On the other hand, C99 introduced a number of new features that C++ did not support that were incompatible or redundant in C++, such as [[variable-length array]]s, native complex-number types (however, the <syntaxhighlight lang="C++" inline>std::complex</syntaxhighlight> class in the C++ standard library provides similar functionality, although not code-compatible), designated initializers, [[C syntax#Compound literals|compound literals]], and the <syntaxhighlight lang="C++" inline>restrict</syntaxhighlight> keyword.<ref>{{cite web |url=http://home.datacomm.ch/t_wolf/tw/c/c9x_changes.html |title=C9X – The New C Standard |accessdate=27 December 2008 }}</ref> Some of the C99-introduced features were included in the subsequent version of the C++ standard, [[C++11#Improved C compatibility|C++11]] (out of those which were not redundant).<ref>{{cite web |title=C++0x Support in GCC |url=https://gcc.gnu.org/projects/cxx0x.html |accessdate=12 October 2010}}</ref><ref>{{cite web |title=C++0x Core Language Features In VC10: The Table |url=https://blogs.msdn.com/b/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx |accessdate=12 October 2010 }}</ref><ref>{{cite web|url=https://clang.llvm.org/cxx_status.html |title=Clang - C++98, C++11, and C++14 Status |publisher=Clang.llvm.org |date=12 May 2013 |accessdate=10 June 2013}}</ref> However, the C++11 standard introduces new incompatibilities, such as disallowing assignment of a string literal to a character pointer, which remains valid C.<br />
<br />
To intermix C and C++ code, any function declaration or definition that is to be called from/used both in C and C++ must be declared with C linkage by placing it within an <syntaxhighlight style=white-space:nowrap lang="C++" inline>extern "C" {/*...*/}</syntaxhighlight> block. Such a function may not rely on features depending on [[name mangling]] (i.e., function overloading).<br />
<br />
== Criticism ==<br />
{{Main|Criticism of C++}}<br />
<br />
Despite its widespread adoption, some notable programmers have criticized the C++ language, including [[Linus Torvalds]],<ref name=torvalds>{{cite mailing list |url=https://lwn.net/Articles/249460/ |title=Re: [RFC] Convert builin-mailinfo.c to use The Better String Library |date=6 September 2007 |accessdate=31 March 2015 }}</ref> [[Richard Stallman]],<ref>{{cite mailing list |url=http://harmful.cat-v.org/software/c++/rms |title=Re: Efforts to attract more users? |date=12 July 2010 |accessdate=31 March 2015 }}</ref> [[Joshua Bloch]], [[Ken Thompson]],<ref>{{cite web |url=https://www.drdobbs.com/open-source/interview-with-ken-thompson/229502480 |title=Dr. Dobb's: Interview with Ken Thompson |author=Andrew Binstock |date=18 May 2011 |accessdate=7 February 2014}}</ref><ref name="Seibel2009">{{cite book|author=Peter Seibel|title=Coders at Work: Reflections on the Craft of Programming|url=https://books.google.com/books?id=nneBa6-mWfgC&pg=PA475|date=16 September 2009|publisher=Apress|isbn=978-1-4302-1948-4|pages=475–476}}</ref><ref name="gigamonkeysWordpress">https://gigamonkeys.wordpress.com/2009/10/16/coders-c-plus-plus/</ref> and [[Donald Knuth]].<ref name="dobbsKnuth">https://www.drdobbs.com/architecture-and-design/an-interview-with-donald-knuth/228700500</ref><ref name="knuth1993">http://tex.loria.fr/litte/knuth-interview</ref><br />
<br />
One of the most often criticised points of C++ is its perceived complexity as a language, with the criticism that a large number of non-orthogonal features in practice necessitates restricting code to subset of C++, thus eschewing the readability benefits of common style and idioms. As expressed by [[Joshua Bloch]]: <blockquote> I think C++ was pushed well beyond its complexity threshold, and yet there are a lot of people programming it. But what you do is you force people to subset it. So almost every shop that I know of that uses C++ says, “Yes, we’re using C++ but we’re not doing multiple-implementation inheritance and we’re not using operator overloading.” There are just a bunch of features that you’re not going to use because the complexity of the resulting code is too high. And I don’t think it’s good when you have to start doing that. You lose this programmer portability where everyone can read everyone else’s code, which I think is such a good thing. </blockquote><br />
<br />
[[Donald Knuth]] (1993, commenting on pre-standardized C++), who said of [[Edsger Dijkstra]] that "to think of programming in C++" "would make him physically ill":<ref name="dobbsKnuth" /><ref name="knuth1993" /> <blockquote> The problem that I have with them today is that... C++ is too complicated. At the moment, it's impossible for me to write portable code that I believe would work on lots of different systems, unless I avoid all exotic features. Whenever the C++ language designers had two competing ideas as to how they should solve some problem, they said "OK, we'll do them both". So the language is too baroque for my taste. </blockquote><br />
<br />
[[Ken Thompson]], who was a colleague of Stroustrup at Bell Labs, gives his assessment:<ref name="Seibel2009" /><ref name="gigamonkeysWordpress" /> <blockquote> It certainly has its good points. But by and large I think it’s a bad language. It does a lot of things half well and it’s just a garbage heap of ideas that are mutually exclusive. Everybody I know, whether it’s personal or corporate, selects a subset and these subsets are different. So it’s not a good language to transport an algorithm—to say, “I wrote it; here, take it.” It’s way too big, way too complex. And it’s obviously [[Design by committee|built by a committee]]. <br />
Stroustrup campaigned for years and years and years, way beyond any sort of technical contributions he made to the language, to get it adopted and used. And he sort of ran all the standards committees with a whip and a chair. And he said “no” to no one. He put every feature in that language that ever existed. It wasn’t cleanly designed—it was just the union of everything that came along. And I think it suffered drastically from that. </blockquote><br />
<br />
However [[Brian Kernighan]], also a colleague at Bell Labs, disputes this assessment:<ref>{{cite video|people=Brian Kernighan|date=July 18, 2018|title=Brian Kernighan Q&A - Computerphile|url=https://www.youtube.com/watch?v=zmYhR8cUX90&t=5m17s}}</ref> <blockquote>C++ has been enormously influential. ... Lots of people say C++ is too big and too complicated etc. etc. but in fact it is a very powerful language and pretty much everything that is in there is there for a really sound reason: it is not somebody doing random invention, it is actually people trying to solve real world problems. Now a lot of the programs that we take for granted today, that we just use, are C++ programs. </blockquote><br />
<br />
Stroustrup himself comments that C++ semantics are much cleaner than its syntax: "within C++, there is a much smaller and cleaner language struggling to get out".<ref>http://www.stroustrup.com/bs_faq.html#really-say-that</ref><br />
<br />
Other complaints may include a lack of [[reflection (computer programming)|reflection]] or [[garbage collection (computer science)|garbage collection]], long compilation times, perceived [[feature creep]],<ref>{{cite web |url=https://commandcenter.blogspot.mx/2012/06/less-is-exponentially-more.html |title=Less is exponentially more |year=2012 |last=Pike |first=Rob}}</ref> and verbose error messages, particularly from template metaprogramming.<ref>{{cite web|url=https://yosefk.com/c++fqa/defective.html|title=Defective C++|first=Yossi|last=Kreinin|date=13 October 2009|accessdate=3 February 2016}}</ref><br />
<br />
== See also ==<br />
{{Portal|Computer programming}}<br />
* [[Comparison of programming languages]]<br />
* [[List of C++ compilers]]<br />
* [[Outline of C++]]<br />
* [[:Category:C++ libraries|C++ Libraries (category)]]<br />
<br />
== References ==<br />
{{Reflist|30em}}<br />
<br />
== Further reading ==<br />
{{Refbegin|30em}}<br />
* {{Cite book |first=David |last=Abrahams |authorlink=David Abrahams (computer programmer) |first2=Aleksey |last2=Gurtovoy |title=C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond |publisher=Addison-Wesley |isbn=0-321-22725-5 }}<br />
* {{Cite book |first=Andrei |last=Alexandrescu |authorlink=Andrei Alexandrescu |year=2001 |title=Modern C++ Design: Generic Programming and Design Patterns Applied |publisher=Addison-Wesley |isbn=0-201-70431-5 }}<br />
* {{Cite book |first=Andrei |last=Alexandrescu |authorlink=Andrei Alexandrescu |first2=Herb |last2=Sutter |authorlink2=Herb Sutter|year=2004 |title=C++ Design and Coding Standards: Rules and Guidelines for Writing Programs |publisher=Addison-Wesley |isbn=0-321-11358-6 }}<br />
* {{Cite book |first=Pete |last=Becker |authorlink=Pete Becker |year=2006 |title=The C++ Standard Library Extensions : A Tutorial and Reference |publisher=Addison-Wesley |isbn=0-321-41299-0 }}<br />
* {{Cite book |first=Frank |last=Brokken |year=2010 |title=C++ Annotations |publisher=University of Groningen |isbn=90-367-0470-7 |url=http://www.icce.rug.nl/documents/cplusplus/ }}<br />
* {{Cite book |first=James O. |last=Coplien |authorlink=James O. Coplien |origyear=reprinted with corrections, original year of publication 1992 |date=1994 |title=Advanced C++: Programming Styles and Idioms |isbn=0-201-54855-0 |url=https://archive.org/details/advancedcbsprogr00copl }}<br />
* {{Cite book |first=Stephen C. |last=Dewhurst |year=2005 |title=C++ Common Knowledge: Essential Intermediate Programming |publisher=Addison-Wesley |isbn=0-321-32192-8 }}<br />
* {{Cite book |author=Information Technology Industry Council |authorlink=Information and Communications Technology Council |publisher=ISO/IEC |location=Geneva |title=Programming languages&nbsp;– C++ |id=14882:2003(E) |edition=Second |date=15 October 2003 }}<br />
* {{Cite book |first=Nicolai M. |last=Josuttis |title=The C++ Standard Library, A Tutorial and Reference |edition=Second|year=2012 |publisher=Addison-Wesley |isbn=0-321-62321-5}}<br />
* {{Cite book |first=Andrew |last=Koenig |authorlink=Andrew Koenig (programmer) |first2=Barbara E. |last2=Moo |year=2000 |title=Accelerated C++ – Practical Programming by Example |publisher=Addison-Wesley |isbn=0-201-70353-X |url=https://archive.org/details/acceleratedcprac2000koen }}<br />
* {{Cite book |first=Stanley B. |last=Lippman |authorlink=Stanley B. Lippman |first2=Josée |last2=Lajoie |first3=Barbara E. |last3=Moo |year=2011|edition=Fifth |title=C++ Primer |url=https://archive.org/details/cprimer0000lipp_5thed |url-access=registration |publisher=Addison-Wesley |isbn= 0-321-71411-3}}<br />
* {{Cite book |first=Stanley B. |last=Lippman |year=1996 |title=Inside the C++ Object Model |publisher=Addison-Wesley |isbn=0-201-83454-5 }}<br />
* {{Cite book |first=Scott |last=Meyers |authorlink=Scott Meyers |year=2005 |title=Effective C++ |edition=Third |publisher=Addison-Wesley |isbn=0-321-33487-6 |url=https://archive.org/details/effectivec55spec00meye }}<br />
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup |year=2013 |title=The C++ Programming Language |edition=Fourth |publisher=Addison-Wesley |isbn=978-0-321-56384-2 }}<br />
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup |year=1994 |title=The Design and Evolution of C++ |publisher=Addison-Wesley |isbn=0-201-54330-3 }}<br />
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup|year=2014 |title=Programming Principles and Practice Using C++ |edition=Second |publisher=Addison-Wesley |isbn=978-0-321-99278-9 }}<br />
* {{Cite book |first=Herb |last=Sutter|authorlink=Herb Sutter |year=2001 |title=More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions |publisher=Addison-Wesley |isbn=0-201-70434-X }}<br />
* {{Cite book |first=Herb |last=Sutter|authorlink=Herb Sutter |year=2004 |title=Exceptional C++ Style |publisher=Addison-Wesley |isbn=0-201-76042-8 }}<br />
* {{Cite book |first=David |last=Vandevoorde |first2=Nicolai M. |last2=Josuttis |year=2003 |title=C++ Templates: The complete Guide |publisher=Addison-Wesley |isbn=0-201-73484-2 }}<br />
{{refend}}<br />
<br />
== External links ==<br />
{{Sister project links|n=no|s=no|b=Subject:C++ programming language}}<br />
* [http://www.open-std.org/jtc1/sc22/wg21/ JTC1/SC22/WG21]{{snd}} the ISO/IEC C++ Standard Working Group<br />
* [https://isocpp.org/ Standard C++ Foundation]{{snd}} a non-profit organization that promotes the use and understanding of standard C++. Bjarne Stroustrup is a director of the organization.<br />
<br />
{{ISO standards}}<br />
{{Programming languages}}<br />
{{C++ programming language}}<br />
{{List of International Electrotechnical Commission standards}}<br />
{{Authority control}}<br />
<br />
{{DEFAULTSORT:C}}<br />
[[Category:Algol programming language family]]<br />
[[Category:C++| ]]<br />
[[Category:C++ programming language family]]<br />
[[Category:Class-based programming languages]]<br />
[[Category:Cross-platform software]]<br />
[[Category:High-level programming languages]]<br />
[[Category:Object-oriented programming languages]]<br />
[[Category:Programming languages created in 1983]]<br />
[[Category:Programming languages with an ISO standard]]<br />
[[Category:Statically typed programming languages]]</div>C++ Trolling Algorithm