WWW W3schools Com CPP CPP - Syntax Asp
WWW W3schools Com CPP CPP - Syntax Asp
com LOG IN
MORE EXERCISES
C++ Syntax
Previous Next
C++ Syntax
Let's break up the following code to understand it better:
Example
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
return 0;
}
Try it Yourself »
Example explained
Line 1: #include <iostream> is a header file library that lets us work with input and output objects, such as
cout (used in line 5). Header files add functionality to C++ programs.
Line 2: using namespace std means that we can use names for objects and variables from the standard library.
Don't worry if you don't understand how #include <iostream> and using namespace std works. Just think of it
as something that (almost) always appears in your program.
Line 4: Another thing that always appear in a C++ program, is int main() . This is called a function. Any code
inside its curly brackets {} will be executed.
Line 5: cout (pronounced "see-out") is an object used together with the insertion operator ( << ) to output/print
text. In our example it will output "Hello World".
Remember: The compiler ignores white spaces. However, multiple lines makes the code more readable.
Line 7: Do not forget to add the closing curly bracket } to actually end the main function.
Omitting Namespace
You might see some C++ programs that runs without the standard namespace library. The using namespace std
line can be omitted and replaced with the std keyword, followed by the :: operator for some objects:
Example
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
Try it Yourself »
Previous Next
COLOR PICKER
LIKE US
Get your
certification today!
View options
HOW TO
Tabs
Dropdowns
Accordions
Side Navigation
Top Navigation
Modal Boxes
Progress Bars
Parallax
Login Form
HTML Includes
Google Maps
Range Sliders
Tooltips
Slideshow
Filter List
Sort List
Certificates
HTML
CSS
JavaScript
Python
SQL
PHP
And more
REPORT ERROR
FORUM
ABOUT
SHOP
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W 3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W 3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W 3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples
Web Certificates
HTML Certificate
CSS Certificate
JavaScript Certificate
SQL Certificate
Python Certificate
PHP Certificate
Bootstrap Certificate
XML Certificate
jQuery Certificate
Get Certified »