Learn C++

The Syntax of C++

Watch The C++ video tutorial and repeat. The easiest way to memorize the C++ (C-Plus-Plus) programing language.

C++ Syntax

To make things easier to comprehend, let’s split down the following code:

				
					#include <iostream>
using namespace std;

int main() {
cout << "Hello Telestudents.com!";
return 0;
}
				
			

Line 1: #include <iostream> is a header file library for working with input and output objects like cout . C++ applications benefit from header files, which provide additional functionality.

Line 2: using namespace std indicates that we may use names from the standard library for objects and variables.

Line 3: Blank Line.
White space in C++ is ignored.
However, we utilize it to improve the readability of the code.

Line 4: int main(). Another constant in a C++ application is int main ().
This is known as a function.
Any code included within the curly brackets {} will be run.

Line 5: cout (pronounced as “see-out”) is an object that works in conjunction with the insertion operator << to output/print text. In our case, the result will be “Hello Telestudents.com!”

Line 6: return 0 terminates the main function.

Line 6: return 0 terminates the main function.

Line 7: Don’t forget to finish the main function with the closing curly bracket }.

If you don’t understand how #include and using namespace std operate, don’t worry.
Consider it something that (nearly) always shows up in your program.

Every C++ statement ends with a semicolon ;.

The body of int main() could also been written as:
int main () { cout << “Hello Telestudents.com! “; return 0; }

Omitting Namespace

Some C++ applications may be found that do not use the standard namespace library.
For some objects, the using namespace std line can be removed and replaced with the std keyword followed by the :: operator:

				
					#include <iostream>

int main() {
  std::cout << "Hello Telestudents.com!";
  return 0;
} 
				
			
Watch The C++ video tutorial and repeat. The easiest way to memorize the C++ (C-Plus-Plus) programing language.
Scroll to Top