Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C++
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Language== {{Main|C++ syntax}} 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|access-date=8 July 2015|title=Stroustrup: Thoughts on C++17 - An Interview|archive-date=8 July 2015|archive-url=https://web.archive.org/web/20150708132155/http://www.infoq.com/news/2015/04/stroustrup-cpp17-interview|url-status=live}}</ref> C++ inherits most of [[C syntax|C's syntax]]. A [[C (programming language)#"Hello, world" example|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]] 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 |access-date=5 May 2014 |archive-date=5 May 2014 |archive-url=https://web.archive.org/web/20140505221112/http://www.stroustrup.com/3rd_issues.html |url-status=live }}</ref><ref group="note">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()"?] {{Webarchive|url=https://web.archive.org/web/20200702224848/http://www.stroustrup.com/bs_faq2.html#void-main |date=2 July 2020 }} 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> <!-- *************************************************************** * * PLEASE NOTE: * * BEFORE MAKING CHANGES to the "Hello World" example * please establish consensus by discussing your proposed changes * on the Talk page. This is not the place to "Be Bold"; this * has been discussed before at length. * * If you change the sample program without discussion, it will be * reverted within a few minutes. * * The latest consensus is ''not'' to make any of those changes. * This is the example "Hello, world!" by Bjarne Stroustrup, * the author of the C++ language, and is used in * his book, "The C++ Programming Language (3rd edition)". * *************************************************************** --><syntaxhighlight lang="cpp" line="1"> #include <iostream> int main() { std::cout << "Hello, world!\n"; } </syntaxhighlight><!-- *** PLEASE NOTE: **** * * BEFORE MAKING CHANGES to the "Hello World" example * please establish consensus by discussing your proposed changes * on the Talk page. This is not the place to "Be Bold"; this * has been discussed before. * * If you change the sample program without discussion, it will be * reverted within a few minutes. * * The latest consensus is ''not'' to make any of those changes. * This is the example "Hello, world!" by Bjarne Stroustrup, * the author of the C++ language, and is used in * his book, "The C++ Programming Language (3rd edition)". * *************************************************************** -->
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)