Changes

6,644 bytes added ,  10:23, 6 September 2023
m
KS update 1.3
Line 1: Line 1: −
:''If you typed '''C#''' and arrived at this page, then see [[C-sharp]].''
+
{{Infobox programming language
{{A-Z}}
+
| name                  = C++
[[File:C cursiva.gif|thumb]]
+
| logo                  = File:ISO C++ Logo.svg
'''C''' is the third ([[three|3rd]]) [[letter]] in the [[English language|English]] [[alphabet]] and [[ISO basic latin alphabet]].
+
| paradigm              = [[Multi-paradigm programming language|Multi-paradigm]]:<ref name="stroustruptcpppl" /> [[procedural programming|procedural]], [[functional programming|functional]], [[object-oriented programming|object-oriented]], [[generic programming|generic]]
== Meanings for C ==
+
| year                  = 1983
* In [[temperature]], ''°C'' means "degrees [[Celsius]]".
+
| designer              = [[Bjarne Stroustrup]]
* In [[music]], ''C'' is a [[Note (music)|note]] sometimes referred to as “Do”.
+
| developer              = Bjarne Stroustrup<br>[[Bell Labs]]<br>{{nobr|ISO/IEC JTC1/SC22/WG21}}
* In [[chemistry]], ''C'' is the atom of [[carbon]], as in '''C'''<sub>40</sub>[[H]]<sub>56</sub>.
+
| latest_release_version = ISO/IEC 14882:2020
* In [[physics]], ''c'' is the [[speed of light]], as in E=mc².
+
| latest_release_date    = {{Start date and age|2020|12|15|df=yes}}
* In [[Roman numeral]]s, ''C'' means "one [[hundred]]" (100).
+
| latest_test_version    =
* There is a [[programming language]] called ''C'', see [[C programming language]].
+
| latest_test_date      =
* In [[electronics]], C is a type of [[battery]].
+
| typing                = [[Static type|Static]], [[Type system#Safely and unsafely typed systems|unsafe]], [[Nominative type system|nominative]]
*C can also mean the [[copyright]] symbol
+
| implementations        = {{nowraplinks}}[[C++ Builder]], [[clang]], [[Comeau C/C++]], [[GNU Compiler Collection|GCC]], [[Intel C++ Compiler]], [[Microsoft Visual C++]], [[Sun Studio (software)|Sun Studio]]{{nowraplinks end}}
== Pronunciation ==
+
| dialects              = {{nowraplinks}}[[ISO/IEC 14882|ISO/IEC C++]] 1998, [[ISO/IEC 14882|ISO/IEC C++]] 2003, [[ISO/IEC 14882|ISO/IEC C++]] 2011, [[ISO/IEC 14882|ISO/IEC C++]] 2014, [[ISO/IEC 14882|ISO/IEC C++]] 2017, [[ISO/IEC 14882|ISO/IEC C++]] 2020{{nowraplinks end}}
*The letter "C" is  pronounced as /k/.We can also say the letter "C" as /s/.
+
| influenced_by          = [[C (programming language)|C]], [[Simula]], [[Ada (programming language)|Ada 83]], [[ALGOL 68]], [[CLU (programming language)|CLU]], [[ML (programming language)|ML]]<ref name="stroustruptcpppl">{{Cite book | last=Stroustrup | first=Bjarne | title=The C++ Programming Language | year=1997 | edition=Third | <!-- chapter=1 | --> isbn=0201889544 | oclc=59193992 }}</ref>
*The letter "C"'s name in English is "ce" (said as  /ˈsiː/).
+
| influenced            = [[Perl]]<!--1987-->, [[LPC (programming language)|LPC]]<!--1989-->, [[Lua]]<!--1993-->, [[Pike (programming language)|Pike]]<!-- 1994 -->, [[Ada (programming language)|Ada 95]]<!--1995-->, [[Java (programming language)|Java]]<!--1995-->, [[PHP]]<!--1995-->, [[D (programming language)|D]]<!--1999-->, [[C99]]<!--1999-->, [[C Sharp (programming language)|C#]]<!--2001-->, [[Falcon (programming language)|Falcon]]<!--2003-->
 +
| operating_system      = [[Cross-platform|Cross-platform (multi-platform)]]
 +
| license                =
 +
| website                =
 +
| file_ext              = .h .hh .hpp .hxx {{nowrap|.h++}} .cc .cpp .cxx {{nowrap|.c++}}
 +
| wikibooks              = C++ Programming
 +
|logo caption=C++ logo used by ISO}}
 +
[[File:BjarneStroustrup.jpg|right|thumb|Bjarne Stroustrup, the creator of C++]]
 +
'''C++''' (pronounced "see plus plus") is a [[computer]] [[programming language]] based on [[C programming language|C]]. It was created for writing programs for many different purposes. In the 1990s, C++ became one of the most used programming languages in the world. Like C, C++ uses manual memory management (unlike most mainstream languages, where memory management is automatic), while the syntax usually used for it is different.
   −
{{wikt}}
+
The C++ programming language was developed by [[Bjarne Stroustrup]] at [[Bell Labs]] in the 1980s, and was originally named "C with classes". The language was planned as an improvement on the [[C (programming language)|C]] programming language, adding features based on [[object-oriented programming]]. Step by step, a lot of advanced features were added to the language, like [[exception handling]], [[templates (programming)|templates]], "move semantics" and [[namespace]]s (not full module support, while that was added later) and new [[operator overloading]] capabilities were added in versions C++11 and C++20.
{{Latin script}}
  −
{{commonscat}}
      +
C++ runs on a most platforms (all mainstream ones), such as [[Windows]], [[macOS]], and the various versions of UNIX, for example [[Linux]]. [https://web.archive.org/web/20200713161758/https://www.programstudio.online/2020/05/introduction-to-c.html Introduction to C++ language] is a practical approach to describe the concepts of C++ for beginners to advanced software engineers.
   −
{{stub}}
+
C++ is a general-purpose programing language which means that it can be used to create different variety of applications. [https://codinggrammar.com/what-is-cpp-used-for/ C++ is used for] variety of application domains.
 +
 
 +
C++20 is the latest version of the standard, which finally added for example module support in December 2020 (while many languages supported modules a decade, if not two or more, earlier). The major compilers have almost complete support for C++20, while almost all default to the older C++17 standard, so a compiler switch is needed to enable the C++20 support the compilers have.
 +
 
 +
New C++ standards are on a three-year schedule, so the next one, C++23, is expected in 2023, and some compilers already have some (partial) support for that experimental standard. The many earlier C++ standards have each added stuff to the language, almost never taken stuff out, so mostly keeping compatibility with older standards.
 +
== Example ==
 +
The following text is C++ source code and it will write the words "[[Hello world program|Hello World!]]" on the screen when it has been [[compiled language|compiled]] and is executed. This program is typically the first program a programmer would write while learning about programming languages.
 +
 
 +
<syntaxhighlight lang="cpp">
 +
// This is a comment. It's for *people* to read, not computers. It's usually used to describe the program.
 +
 
 +
// Make the I/O standard library available for use in the program.
 +
#include <iostream>
 +
 
 +
// We are now defining the main function; it is the function run when the program starts.
 +
int main()
 +
{
 +
    // Printing a message to the screen using the standard output stream std::cout.
 +
    std::cout << "Hello World!";
 +
    return 0;
 +
}
 +
</syntaxhighlight>
 +
 
 +
This program is similar to the last, except it will add 3 + 2 and print the answer instead of "Hello World!".
 +
 
 +
<syntaxhighlight lang="cpp">
 +
#include <iostream>
 +
 
 +
int main()
 +
{
 +
    // Print a simple calculation.
 +
    std::cout << 3 + 2;
 +
    return 0;
 +
}
 +
</syntaxhighlight>
 +
 
 +
This program subtracts, multiplies, divides and then prints the answer on the screen.
 +
 
 +
<syntaxhighlight lang="cpp">
 +
#include <iostream>
 +
 
 +
int main()
 +
{
 +
    // Create and initialize three variables, a, b, and c, to 5, 10, and 20.
 +
    int a = 5;
 +
    int b = 10;
 +
    int c = 20;
 +
 
 +
    // Print calculations.
 +
    std::cout << a-b-c;
 +
    std::cout << a*b*c;
 +
    std::cout << a/b/c;
 +
    return 0;
 +
}
 +
</syntaxhighlight>
 +
== Manual memory management ==
 +
C++ introduced two keywords <code>new</code> and <code>delete</code> for manual memory management (while also keeping compatibility with the old way C uses), and the constructor and destructor concepts. In modern C++ code, using <code>new</code> and <code>delete</code> (and destructors) is no longer preferred in high-level code, rather containers such as <code>std:vector</code> (which at a low level are implemented with <code>new</code> and <code>delete</code>).
 +
 
 +
== C++ Media ==
 +
<gallery widths='160px' heights='100%' mode='traditional' caption=''>
 +
File:20160121 CppFRUG Joel Falcou CppQuiz 3.jpg|A quiz on C++11 features being given in Paris in 2015
 +
 
 +
File:C++ Standards Committee meeting - July 1996 Stockholm - Wednesday general session.jpg|Scene during the C++ standards committee meeting in Stockholm in 1996
 +
 
 +
File:ANSI ISO C++ WP.jpg|The draft "Working Paper" standard that became approved as C++98; half of its size was devoted to the C++ Standard Library.
 +
</gallery>
 +
== References ==
 +
{{reflist}}
 +
 
 +
{{Tech-stub}}
 +
{{authority control}}
 +
[[Category:Multi-paradigm programming languages]]
 +
[[Category:Object-oriented programming languages]]
 +
[[Category:Cross-platform software]]