C Compilers
   HOME

TheInfoList



OR:

C++ (, pronounced "C plus plus" and sometimes abbreviated as CPP or CXX) is a high-level,
general-purpose programming language In computer software, a general-purpose programming language (GPL) is a programming language for building software in a wide variety of application Domain (software engineering), domains. Conversely, a Domain-specific language, domain-specific pro ...
created by Danish computer scientist Bjarne Stroustrup. First released in 1985 as an extension of the
C programming language C (''pronounced'' '' – like the letter c'') is a general-purpose programming language. It was created in the 1970s by Dennis Ritchie and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of ...
, adding
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impleme ...
(OOP) features, it has since expanded significantly over time adding more OOP and other features; /C++98 standardization, C++ has added functional features, in addition to facilities for low-level
memory Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembe ...
manipulation for systems like
microcomputer A microcomputer is a small, relatively inexpensive computer having a central processing unit (CPU) made out of a microprocessor. The computer also includes memory and input/output (I/O) circuitry together mounted on a printed circuit board (P ...
s or to make operating systems like
Linux Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
or
Windows Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
, and even later came features like generic ( template) programming. C++ is usually implemented as a
compiled language Compiled language categorizes a programming language as used with a compiler and generally implies not used with an interpreter. But, since any language can theoretically be compiled or interpreted the term lacks clarity. In practice, for some lan ...
, and many vendors provide C++ compilers, including the
Free Software Foundation The Free Software Foundation (FSF) is a 501(c)(3) non-profit organization founded by Richard Stallman on October 4, 1985. The organisation supports the free software movement, with the organization's preference for software being distributed ...
,
LLVM LLVM, also called LLVM Core, is a target-independent optimizer and code generator. It can be used to develop a Compiler#Front end, frontend for any programming language and a Compiler#Back end, backend for any instruction set architecture. LLVM i ...
,
Microsoft Microsoft Corporation is an American multinational corporation and technology company, technology conglomerate headquartered in Redmond, Washington. Founded in 1975, the company became influential in the History of personal computers#The ear ...
,
Intel Intel Corporation is an American multinational corporation and technology company headquartered in Santa Clara, California, and Delaware General Corporation Law, incorporated in Delaware. Intel designs, manufactures, and sells computer compo ...
, Embarcadero,
Oracle An oracle is a person or thing considered to provide insight, wise counsel or prophetic predictions, most notably including precognition of the future, inspired by deities. If done through occultic means, it is a form of divination. Descript ...
, and
IBM International Business Machines Corporation (using the trademark IBM), nicknamed Big Blue, is an American Multinational corporation, multinational technology company headquartered in Armonk, New York, and present in over 175 countries. It is ...
. C++ was designed with
systems programming Systems programming, or system programming, is the activity of programming computer system software. The primary distinguishing characteristic of systems programming when compared to application programming is that application programming aims t ...
and embedded, resource-constrained software and large systems in mind, with
performance A performance is an act or process of staging or presenting a play, concert, or other form of entertainment. It is also defined as the action or process of carrying out or accomplishing an action, task, or function. Performance has evolved glo ...
, efficiency, and flexibility of use as its design highlights. C++ has also been found useful in many other contexts, with key strengths being software infrastructure and resource-constrained applications, including desktop applications,
video games A video game or computer game is an electronic game that involves interaction with a user interface or input device (such as a joystick, game controller, controller, computer keyboard, keyboard, or motion sensing device) to generate visual fe ...
, servers (e.g.,
e-commerce E-commerce (electronic commerce) refers to commercial activities including the electronic buying or selling products and services which are conducted on online platforms or over the Internet. E-commerce draws on technologies such as mobile co ...
, web search, or
database In computing, a database is an organized collection of data or a type of data store based on the use of a database management system (DBMS), the software that interacts with end users, applications, and the database itself to capture and a ...
s), and performance-critical applications (e.g., telephone switches or space probes). C++ is standardized by the
International Organization for Standardization The International Organization for Standardization (ISO ; ; ) is an independent, non-governmental, international standard development organization composed of representatives from the national standards organizations of member countries. M ...
(ISO), with the latest standard version ratified and published by ISO in October 2024 as ''ISO/IEC 14882:2024'' (informally known as
C++23 C++23, formally ISO/IEC 14882:2024, is the current open standard for the C++ programming language that follows C++20. The final draft of this version is N4950. In February 2020, at the final meeting for C++20 in Prague, an overall plan for C++ ...
). The C++ programming language was initially standardized in 1998 as ''ISO/IEC 14882:1998'', which was then amended by the
C++03 C++03 is a version of the ISO/ IEC 14882 standard for the C++ programming language. It is defined by two standards organizations, the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC), in ...
,
C++11 C++11 is a version of a joint technical standard, ISO/IEC 14882, by the International Organization for Standardization (ISO) and International Electrotechnical Commission (IEC), for the C++ programming language. C++11 replaced the prior vers ...
,
C++14 C14, C.XIV or C-14 may refer to: Time * The 14th century * Carbon-14, a radioactive isotope of carbon ** Radiocarbon dating, C-14 dating, a method for dating events Science * IEC 60320#C14, IEC 60320 C14, a polarised, three pole socket electrical ...
,
C++17 C17, C-17 or C.17 may refer to: Transportation * , a 1917 British C-class submarine Air * Boeing C-17 Globemaster III, a military transport aircraft * Lockheed Y1C-17 Vega, a six-passenger monoplane * Cierva C.17, a 1928 English experimental ...
, and
C++20 C20 or C-20 may refer to: Science and technology * Carbon-20 (C-20 or 20C), an isotope of carbon * C20, the smallest possible fullerene (a carbon molecule) * C20 (engineering), a mix of concrete that has a compressive strength of 20 newtons per squ ...
standards. The current standard supersedes these with new features and an enlarged
standard library In computer programming, a standard library is the library (computing), library made available across Programming language implementation, implementations of a programming language. Often, a standard library is specified by its associated program ...
. Before the initial standardization in 1998, C++ was developed by Stroustrup at
Bell Labs Nokia Bell Labs, commonly referred to as ''Bell Labs'', is an American industrial research and development company owned by Finnish technology company Nokia. With headquarters located in Murray Hill, New Jersey, Murray Hill, New Jersey, the compa ...
since 1979 as an extension of the C language; he wanted an efficient and flexible language similar to C that also provided high-level features for program organization. Since 2012, C++ has been on a three-year release schedule with
C++26 C26 or C-26 may refer to: * C.26, a British World War I Coastal class airship * C26 road (Namibia) * Caldwell 26, a spiral galaxy * Caspar C 26, German sport plane * Douglas C-26 Dolphin, an American military flying boat * Fairchild C-26 Metro ...
as the next planned standard. Despite its widespread adoption, some notable programmers have criticized the C++ language, including
Linus Torvalds Linus Benedict Torvalds ( , ; born 28 December 1969) is a Finnish software engineer who is the creator and lead developer of the Linux kernel. He also created the distributed version control system Git. He was honored, along with Shinya Yam ...
,
Richard Stallman Richard Matthew Stallman ( ; born March 16, 1953), also known by his initials, rms, is an American free software movement activist and programmer. He campaigns for software to be distributed in such a manner that its users have the freedom to ...
, Joshua Bloch,
Ken Thompson Kenneth Lane Thompson (born February 4, 1943) is an American pioneer of computer science. Thompson worked at Bell Labs for most of his career where he designed and implemented the original Unix operating system. He also invented the B (programmi ...
, and
Donald Knuth Donald Ervin Knuth ( ; born January 10, 1938) is an American computer scientist and mathematician. He is a professor emeritus at Stanford University. He is the 1974 recipient of the ACM Turing Award, informally considered the Nobel Prize of comp ...
..


History

In 1979, Bjarne Stroustrup, a Danish
computer scientist A computer scientist is a scientist who specializes in the academic study of computer science. Computer scientists typically work on the theoretical side of computation. Although computer scientists can also focus their work and research on ...
, began work on "", the predecessor to C++. The motivation for creating a new language originated from Stroustrup's experience in programming for his PhD thesis. Stroustrup found that
Simula Simula is the name of two simulation programming languages, Simula I and Simula 67, developed in the 1960s at the Norwegian Computing Center in Oslo, by Ole-Johan Dahl and Kristen Nygaard. Syntactically, it is an approximate superset of AL ...
had features that were very helpful for large software development, but the language was too slow for practical use, while
BCPL BCPL ("Basic Combined Programming Language") is a procedural, imperative, and structured programming language. Originally intended for writing compilers for other languages, BCPL is no longer in common use. However, its influence is still f ...
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 (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
kernel with respect to
distributed computing Distributed computing is a field of computer science that studies distributed systems, defined as computer systems whose inter-communicating components are located on different networked computers. The components of a distributed system commu ...
. Remembering his PhD experience, Stroustrup set out to enhance the C language with Simula-like features. C was chosen because it was general-purpose, fast, portable, and widely used. In addition to C and Simula's influences, other languages influenced this new language, including
ALGOL 68 ALGOL 68 (short for ''Algorithmic Language 1968'') is an imperative programming language member of the ALGOL family that was conceived as a successor to the ALGOL 60 language, designed with the goal of a much wider scope of application and ...
, Ada, CLU, and ML. Initially, Stroustrup's "C with Classes" added features to the C compiler, Cpre, including classes, derived classes,
strong typing In computer programming, one of the many ways that programming languages are colloquially classified is whether the language's type system makes it strongly typed or weakly typed (loosely typed). However, there is no precise technical definition o ...
, inlining, and default arguments. In 1982, Stroustrup started to develop a successor to C with Classes, which he named "C++" (++ being the increment operator in C) after going through several other names. New features were added, including
virtual function In object-oriented programming such as is often used in C++ and Object Pascal, a virtual function or virtual method is an inheritable and overridable function or method that is dispatched dynamically. Virtual functions are an important part ...
s, function name and
operator overloading In computer programming, operator overloading, sometimes termed ''operator ad hoc polymorphism'', is a specific case of polymorphism, where different operators have different implementations depending on their arguments. Operator overloading ...
,
reference A reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''nam ...
s, constants, type-safe free-store memory allocation (new/delete), improved type checking, and BCPL-style single-line comments with two forward slashes (//). Furthermore, Stroustrup developed a new, standalone compiler for C++, Cfront. In 1984, Stroustrup implemented the first stream input/output library. The idea of providing an output operator rather than a named output function was suggested by
Doug McIlroy Malcolm Douglas McIlroy (born 1932) is an American mathematician, engineer, and programmer. As of 2019 he is an Adjunct Professor of Computer Science at Dartmouth College. McIlroy is best known for having originally proposed Unix pipelines and de ...
(who had previously suggested Unix pipes). 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. The first commercial implementation of C++ was released in October of the same year. In 1989, C++ 2.0 was released, followed by the updated second edition of ''The C++ Programming Language'' in 1991. New features in 2.0 included multiple inheritance, abstract classes, static member functions, 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 templates, exceptions,
namespaces In computing, a namespace is a set of signs (''names'') that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified. Namespaces ...
, new
cast Cast may refer to: Music * Cast (band), an English alternative rock band * Cast (Mexican band), a progressive Mexican rock band * The Cast, a Scottish musical duo: Mairi Campbell and Dave Francis * ''Cast'', a 2012 album by Trespassers William ...
s, and a Boolean type. In 1998, C++98 was released, standardizing the language, and a minor update (
C++03 C++03 is a version of the ISO/ IEC 14882 standard for the C++ programming language. It is defined by two standards organizations, the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC), in ...
) was released in 2003. After C++98, C++ evolved relatively slowly until, in 2011, the
C++11 C++11 is a version of a joint technical standard, ISO/IEC 14882, by the International Organization for Standardization (ISO) and International Electrotechnical Commission (IEC), for the C++ programming language. C++11 replaced the prior vers ...
standard was released, adding numerous new features, enlarging the standard library further, and providing more facilities to C++ programmers. After a minor update released in December 2014, various new additions were introduced in
C++17 C17, C-17 or C.17 may refer to: Transportation * , a 1917 British C-class submarine Air * Boeing C-17 Globemaster III, a military transport aircraft * Lockheed Y1C-17 Vega, a six-passenger monoplane * Cierva C.17, a 1928 English experimental ...
. After becoming finalized in February 2020, a draft of the C++20 standard was approved on 4 September 2020, and officially published on 15 December 2020. On January 3, 2018, Stroustrup was announced as the 2018 winner of the
Charles Stark Draper Prize The U.S. National Academy of Engineering annually awards the Draper Prize, which is given for the advancement of engineering and the education of the public about engineering. It is one of three prizes that constitute the "Nobel Prizes of Enginee ...
for Engineering, "for conceptualizing and developing the C++ programming language". In December 2022, C++ ranked third on the TIOBE index, surpassing
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
for the first time in the history of the index. , the language ranks second after Python, with Java being in third. In March 2025, Stroustrup issued a call for the language community to defend it. Since the language allows manual memory management, bugs that represent security risks such as buffer overflow may be introduced in programs when inadvertently misused by the programmer.


Etymology

According to Stroustrup, "the name signifies the evolutionary nature of the changes from C." This name is credited to Rick Mascitti (mid-1983) 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 ++ operator (which increments the value of a variable) and a common naming convention of using "+" to indicate an enhanced computer program. During C++'s development period, the language had been referred to as "new C" and "C with Classes" before acquiring its final name.


Philosophy

Throughout C++'s life, its development and evolution has been guided by a set of principles: * It must be driven by actual problems and its features should be immediately useful in real world programs. * Every feature should be implementable (with a reasonably obvious way to do so). * Programmers should be free to pick their own programming style, and that style should be fully supported by C++. * Allowing a useful feature is more important than preventing every possible misuse of C++. * It should provide facilities for organizing programs into separate, well-defined parts, and provide facilities for combining separately developed parts. * No implicit violations of the
type system In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usu ...
(but allow explicit violations; that is, those explicitly requested by the programmer). * User-created types need to have the same support and performance as built-in types. * Unused features should not negatively impact created executables (e.g. in lower performance). * There should be no language beneath C++ (except
assembly language In computing, assembly language (alternatively assembler language or symbolic machine code), often referred to simply as assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence bet ...
). * C++ should work alongside other existing
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s, rather than fostering its own separate and incompatible programming environment. * If the programmer's intent is unknown, allow the programmer to specify it by providing manual control.


Standardization

C++ is standardized by an
ISO The International Organization for Standardization (ISO ; ; ) is an independent, non-governmental, international standard development organization composed of representatives from the national standards organizations of member countries. Me ...
working group known as JTC1/SC22/WG21. So far, it has published seven revisions of the C++ standard and is currently working on the next revision,
C++26 C26 or C-26 may refer to: * C.26, a British World War I Coastal class airship * C26 road (Namibia) * Caldwell 26, a spiral galaxy * Caspar C 26, German sport plane * Douglas C-26 Dolphin, an American military flying boat * Fairchild C-26 Metro ...
. 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. The next major revision of the standard was informally referred to as "C++0x", but it was not released until 2011.
C++11 C++11 is a version of a joint technical standard, ISO/IEC 14882, by the International Organization for Standardization (ISO) and International Electrotechnical Commission (IEC), for the C++ programming language. C++11 replaced the prior vers ...
(14882:2011) included many additions to both the core language and the standard library. In 2014,
C++14 C14, C.XIV or C-14 may refer to: Time * The 14th century * Carbon-14, a radioactive isotope of carbon ** Radiocarbon dating, C-14 dating, a method for dating events Science * IEC 60320#C14, IEC 60320 C14, a polarised, three pole socket electrical ...
(also known as C++1y) was released as a small extension to C++11, featuring mainly bug fixes and small improvements. The Draft International Standard ballot procedures completed in mid-August 2014. After C++14, a major revision
C++17 C17, C-17 or C.17 may refer to: Transportation * , a 1917 British C-class submarine Air * Boeing C-17 Globemaster III, a military transport aircraft * Lockheed Y1C-17 Vega, a six-passenger monoplane * Cierva C.17, a 1928 English experimental ...
, informally known as C++1z, was completed by the ISO C++ committee in mid July 2017 and was approved and published in December 2017. As part of the standardization process, ISO also publishes technical reports and specifications: * ISO/IEC TR 18015:2006 on the use of C++ in embedded systems and on performance implications of C++ language and library features, * ISO/IEC TR 19768:2007 (also known as the C++ Technical Report 1) on library extensions mostly integrated into
C++11 C++11 is a version of a joint technical standard, ISO/IEC 14882, by the International Organization for Standardization (ISO) and International Electrotechnical Commission (IEC), for the C++ programming language. C++11 replaced the prior vers ...
, * ISO/IEC TR 29124:2010 on special mathematical functions, integrated into , * ISO/IEC TR 24733:2011 on decimal floating-point arithmetic, * ISO/IEC TS 18822:2015 on the standard filesystem library, integrated into
C++17 C17, C-17 or C.17 may refer to: Transportation * , a 1917 British C-class submarine Air * Boeing C-17 Globemaster III, a military transport aircraft * Lockheed Y1C-17 Vega, a six-passenger monoplane * Cierva C.17, a 1928 English experimental ...
, * ISO/IEC TS 19570:2015 on parallel versions of the standard library algorithms, integrated into
C++17 C17, C-17 or C.17 may refer to: Transportation * , a 1917 British C-class submarine Air * Boeing C-17 Globemaster III, a military transport aircraft * Lockheed Y1C-17 Vega, a six-passenger monoplane * Cierva C.17, a 1928 English experimental ...
, * ISO/IEC TS 19841:2015 on software
transactional memory In computer science and computer engineering, engineering, transactional memory attempts to simplify concurrent programming by allowing a group of load and store instructions to execute in an linearizability, atomic way. It is a concurrency control ...
, * ISO/IEC TS 19568:2015 on a new set of library extensions, some of which are already integrated into
C++17 C17, C-17 or C.17 may refer to: Transportation * , a 1917 British C-class submarine Air * Boeing C-17 Globemaster III, a military transport aircraft * Lockheed Y1C-17 Vega, a six-passenger monoplane * Cierva C.17, a 1928 English experimental ...
, * ISO/IEC TS 19217:2015 on the C++
concepts A concept is an abstract idea that serves as a foundation for more concrete principles, thoughts, and beliefs. Concepts play an important role in all aspects of cognition. As such, concepts are studied within such disciplines as linguistics, psy ...
, integrated into
C++20 C20 or C-20 may refer to: Science and technology * Carbon-20 (C-20 or 20C), an isotope of carbon * C20, the smallest possible fullerene (a carbon molecule) * C20 (engineering), a mix of concrete that has a compressive strength of 20 newtons per squ ...
, * ISO/IEC TS 19571:2016 on the library extensions for concurrency, some of which are already integrated into
C++20 C20 or C-20 may refer to: Science and technology * Carbon-20 (C-20 or 20C), an isotope of carbon * C20, the smallest possible fullerene (a carbon molecule) * C20 (engineering), a mix of concrete that has a compressive strength of 20 newtons per squ ...
, * ISO/IEC TS 19568:2017 on a new set of general-purpose library extensions, * ISO/IEC TS 21425:2017 on the library extensions for ranges, integrated into
C++20 C20 or C-20 may refer to: Science and technology * Carbon-20 (C-20 or 20C), an isotope of carbon * C20, the smallest possible fullerene (a carbon molecule) * C20 (engineering), a mix of concrete that has a compressive strength of 20 newtons per squ ...
, * ISO/IEC TS 22277:2017 on coroutines, integrated into
C++20 C20 or C-20 may refer to: Science and technology * Carbon-20 (C-20 or 20C), an isotope of carbon * C20, the smallest possible fullerene (a carbon molecule) * C20 (engineering), a mix of concrete that has a compressive strength of 20 newtons per squ ...
, * ISO/IEC TS 19216:2018 on the networking library, * ISO/IEC TS 21544:2018 on modules, integrated into
C++20 C20 or C-20 may refer to: Science and technology * Carbon-20 (C-20 or 20C), an isotope of carbon * C20, the smallest possible fullerene (a carbon molecule) * C20 (engineering), a mix of concrete that has a compressive strength of 20 newtons per squ ...
, * ISO/IEC TS 19570:2018 on a new set of library extensions for parallelism * ISO/IEC TS 23619:2021 on new extensions for
reflective programming In computer science, reflective programming or reflection is the ability of a process to examine, introspect, and modify its own structure and behavior. Historical background The earliest computers were programmed in their native assembly lang ...
(reflection), * ISO/IEC TS 9922:2024 on new set of concurrency extensions, and * ISO/IEC TS 19568:2024 on another new set of library extensions. More technical specifications are in development and pending approval.


Language

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 esignedfor building and using efficient and elegant abstractions"; and "offering both hardware access and abstraction is the basis of C++. Doing it efficiently is what distinguishes it from other languages." C++ inherits most of C's syntax. A hello world program that conforms to the C standard is also a valid C++ hello world program. The following is Bjarne Stroustrup's version of the
Hello world program Hello is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses ''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the '' Norwich Cou ...
that uses the
C++ Standard Library The C standard library, sometimes referred to as libc, is the standard library for the C programming language, as specified in the ISO C standard.ISO/ IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the origina ...
stream facility to write a message to
standard output Standard may refer to: Symbols * Colours, standards and guidons, kinds of military signs * Standard (emblem), a type of a large symbol or emblem used for identification Norms, conventions or requirements * Standard (metrology), an object t ...
:This code is copied directly from Bjarne Stroustrup's errata page (p. 633). He addresses the use of '\n' rather than std::endl. Also se
Can I write "void main()"?
for an explanation of the implicit return 0; in the main function. This implicit return is ''not'' available in other functions.
#include int main()


Standard library

The C++ 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 ( vectors, lists, maps, sets, queues, stacks, arrays, tuples),
algorithm In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
s (find, for_each,
binary_search In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the m ...
, random_shuffle, etc.), input/output facilities ( iostream, for reading from and writing to the console and files), filesystem library, localisation support,
smart pointers In computer science, a smart pointer is an abstract data type that simulates a Pointer (computer programming), pointer while providing added features, such as automatic memory management or bounds checking. Such features are intended to reduce ...
for automatic memory management,
regular expression A regular expression (shortened as regex or regexp), sometimes referred to as rational expression, is a sequence of characters that specifies a match pattern in text. Usually such patterns are used by string-searching algorithms for "find" ...
support, 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 does not use C++ exceptions into C++ exceptions, a
random number generator Random number generation is a process by which, often by means of a random number generator (RNG), a sequence of numbers or symbols is generated that cannot be reasonably predicted better than by random chance. This means that the particular ou ...
, and a slightly modified version of the
C standard library The C standard library, sometimes referred to as libc, is the standard library for the C (programming language), C programming language, as specified in the ISO C standard.International Organization for Standardization, ISO/International Electrote ...
(to make it comply with the C++ type system). A large part of the C++ library is based on the
Standard Template Library The Standard Template Library (STL) is a software library originally designed by Alexander Stepanov for the C++ programming language that influenced many parts of the C++ Standard Library. It provides four components called ''algorithms'', '' ...
(STL). Useful tools provided by the STL include
container A container is any receptacle or enclosure for holding a product used in storage, packaging, and transportation, including shipping. Things kept inside of a container are protected on several sides by being inside of its structure. The term ...
s as the collections of objects (such as
vector Vector most often refers to: * Euclidean vector, a quantity with a magnitude and a direction * Disease vector, an agent that carries and transmits an infectious pathogen into another living organism Vector may also refer to: Mathematics a ...
s and lists),
iterator In computer programming, an iterator is an object that progressively provides access to each item of a collection, in order. A collection may provide multiple iterators via its interface that provide items in different orders, such as forwards ...
s that provide array-like access to containers, and
algorithm In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
s that perform operations such as searching and sorting. Furthermore, (multi)maps (
associative array In computer science, an associative array, key-value store, map, symbol table, or dictionary is an abstract data type that stores a collection of (key, value) pairs, such that each possible key appears at most once in the collection. In math ...
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 Feature may refer to: Computing * Feature recognition, could be a hole, pocket, or notch * Feature (computer vision), could be an edge, corner or blob * Feature (machine learning), in statistics: individual measurable properties of the phenome ...
s of the
library A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
may be accessed by using the #include directive to include a standard header. The
C++ Standard Library The C standard library, sometimes referred to as libc, is the standard library for the C programming language, as specified in the ISO C standard.ISO/ IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the origina ...
provides 105 standard headers, of which 27 are deprecated. With the introduction of modules in
C++20 C20 or C-20 may refer to: Science and technology * Carbon-20 (C-20 or 20C), an isotope of carbon * C20, the smallest possible fullerene (a carbon molecule) * C20 (engineering), a mix of concrete that has a compressive strength of 20 newtons per squ ...
, these headers may be accessed with import, and in
C++23 C++23, formally ISO/IEC 14882:2024, is the current open standard for the C++ programming language that follows C++20. The final draft of this version is N4950. In February 2020, at the final meeting for C++20 in Prague, an overall plan for C++ ...
, the entire standard library can now be directly imported as module itself, with import std;. Currently, the C++ standard library provides two modules, std and std.compat (a compatibility module for std which exports C standard library facilities into the global namespace). 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.). Most C++ compilers, and all major ones, provide a standards-conforming implementation of the C++ standard library.


C++ Core Guidelines

The C++ Core Guidelines are an initiative led by Bjarne Stroustrup, the inventor of C++, and Herb Sutter, the convener and chair of the C++ ISO Working Group, to help programmers write 'Modern C++' by using best practices for the language standards C++11 and newer, and to help developers of compilers and static checking tools to create rules for catching bad programming practices. The main aim is to efficiently and consistently write type and resource safe C++. The Core Guidelines were announced in the opening keynote at CPPCon 2015. The Guidelines are accompanied by the Guideline Support Library (GSL), a header only library of types and functions to implement the Core Guidelines and static checker tools for enforcing Guideline rules.


Compatibility

To give compiler vendors greater freedom, the C++ standards committee decided not to dictate the implementation of
name mangling In compiler construction, name mangling (also called name decoration) is a technique used to solve various problems caused by the need to resolve unique names for programming entities in many modern programming languages. It provides means to e ...
,
exception handling In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
, and other implementation-specific features. The downside of this decision is that
object code In computing, object code or object module is the product of an assembler or compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' ...
produced by different
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
s is expected to be incompatible. There are, however, attempts to standardize compilers for particular machines or
operating system An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ...
s. For example, the Itanium C++ ABI is processor-independent (despite its name) and is implemented by GCC and Clang.


With C

C++ is often considered to be a superset of C but this is not strictly true. 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 void* to other pointer types but C++ does not (for type safety reasons). Also, C++ defines many new keywords, such as new and class, which may be used as identifiers (for example, variable names) in a C program. Some incompatibilities have been removed by the 1999 revision of the C standard ( C99), which now supports C++ features such as line comments (//) 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 In computer programming, a variable-length array (VLA), also called variable-sized or runtime-sized, is an array data structure whose length is determined at runtime, instead of at compile time. In the language C, the VLA is said to have a variab ...
s, native complex-number types (however, the std::complex class in the C++ standard library provides similar functionality, although not code-compatible), designated initializers, compound literals, and the restrict keyword. Some of the C99-introduced features were included in the subsequent version of the C++ standard,
C++11 C++11 is a version of a joint technical standard, ISO/IEC 14882, by the International Organization for Standardization (ISO) and International Electrotechnical Commission (IEC), for the C++ programming language. C++11 replaced the prior vers ...
(out of those which were not redundant). However, the C++11 standard introduces new incompatibilities, such as disallowing assignment of a string literal to a character pointer, which remains valid C. 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 extern "C" block. Such a function may not rely on features depending on
name mangling In compiler construction, name mangling (also called name decoration) is a technique used to solve various problems caused by the need to resolve unique names for programming entities in many modern programming languages. It provides means to e ...
(i.e., function overloading).


Inline assembly

Programs developed in C or C++ often utilize inline assembly to take advantage of its low-level functionalities, greater speed, and enhanced control compared to high-level programming languagesBokil, Milind A. (2021).
Writing Assembly Routines within C/C++ and Java Programs
. ResearchGate. Retrieved 1 April 2025.
when optimizing for performance is essential. C++ provides support for embedding assembly language using asm declarations,cppreference.com contributors.
asm declaration
. ''cppreference.com''. Retrieved 1 April 2025.
but the compatibility of
inline assembly In computer programming, an inline assembler is a feature of some compilers that allows low-level code written in assembly language to be embedded within a program, among code that otherwise has been compiled from a higher-level language such as ...
varies significantly between
compilers In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs tha ...
and architectures. Unlike high-level language features such as Python or
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
, assembly code is highly dependent on the underlying processor and compiler implementation.


Variations across compilers

Different C++ compilers implement inline assembly in distinct ways. * GCC (
GNU Compiler Collection The GNU Compiler Collection (GCC) is a collection of compilers from the GNU Project that support various programming languages, Computer architecture, hardware architectures, and operating systems. The Free Software Foundation (FSF) distributes ...
) and
Clang Clang () is a compiler front end for the programming languages C, C++, Objective-C, Objective-C++, and the software frameworks OpenMP, OpenCL, RenderScript, CUDA, SYCL, and HIP. It acts as a drop-in replacement for the GNU Compiler ...
: Use the GCC extended inline assembly syntax. Using __asm__ keyword instead of asm when writing code that can be compiled with -ansi and -std options, which allows specifying input/output operands and clobbered registers. This approach is widely adopted, including by IntelIntel Corporation.
Inline Assembly
. ''Intel® C++ Compiler Classic Developer Guide and Reference'', Version 2021.9. Retrieved 1 April 2025.
and IBMIBM.
Inline assembly statements (IBM extension)
. ''IBM Documentation''. Retrieved 1 April 2025.
compilers. * MSVC ( Microsoft Visual C++): The inline assembler is built into the compiler. Previously supported inline assembly via the __asm keyword, but this support has been removed in 64-bit mode, requiring separate .asm modules instead. * TI ARM Clang and Embedded Compilers: Some embedded system compilers, like Texas Instruments' TI Arm Clang, allow inline assembly but impose stricter rules to avoid conflicts with register conventions and calling conventions.


Interoperability between C++ and Assembly

C++ provides two primary methods of integrating ASM code. 1. Standalone assembly files – Assembly code is written separately and linked with C++ code. 2.
Inline assembly In computer programming, an inline assembler is a feature of some compilers that allows low-level code written in assembly language to be embedded within a program, among code that otherwise has been compiled from a higher-level language such as ...
– Assembly code is embedded within C++ code using compiler-specific extensions. ;Example Code for ASM Compatibility * When calling an assembly function from C++, use extern "C" to prevent C++ name mangling. //main.cpp import std; extern "C" int add_asm(int, int); // Declare the assembly function int main() #asm code using RISC-V architecture .section .text .global add_asm add_asm: add a0, a0, a1 # Add first argument (a0) and second argument (a1), store in a0 ret # Return (a0 holds return value) *Global variables in assembly must be declared as extern in C++ and marked .global in assembly. // main.cpp import std; extern "C" int global_var; // Declare global variable from assembly int main() #asm using RISC-V architecture .section .data .global global_var .align 4 global_var: .word 42 # Define integer value * Inline assembly allows embedding ASM directly in C++ using the asm keyword. //main.cpp (using GCC/CLANG compiler) import std; int main()


See also

* Carbon (programming language) * Comparison of programming languages * List of C++ compilers * Outline of C++ * :C++ libraries


Footnotes


References


Further reading

* * * * * * * * * * * * * * * * * * *


External links


JTC1/SC22/WG21
– the ISO/IEC C++ Standard Working Group
Standard C++ Foundation
– a non-profit organization that promotes the use and understanding of standard C++. Bjarne Stroustrup is a director of the organization.
C++ Keywords

C++ Expressions

C++ Operator Precedence
{{DEFAULTSORT:C Algol programming language family C++ programming language family Class-based programming languages Cross-platform software High-level programming languages Object-oriented programming languages Programming languages created in 1983 Programming languages with an ISO standard Statically typed programming languages Compiled programming languages Articles with example C++ code