C++ Syntax - Learn C++ programming

Today, We will Learn C++ Syntax – Learn C++ programming, C++ has many Syntax but, here We talk some one’s, so learn carefully. Learn C++ is Continue.

Hello! In this chapter, we will talk about C++ syntax for the sack of Learn C++ Programming and Readers! I also write and upload previous articles series about C++ programming.

Learn C++ programming topics:

#include <iostream>
using namespace std;
int main(){

    cout << "Hello World!";
    return 0;
}

Output:

Hello World!

Line no# 1:

We use this #include <iostream> is a header file library. which we perform basic action/function, like input and output objects, such as cout (we have used this in Line no# 6). The header file adds functionality to the C++ programs.

Line no# 2:

using namespace std; mean’s that we can use the names, variables, and other functionalities of objects from the standard library.

If you do not understand #include <iostream> and using namespace std; C++ syntax. Don’t Worry! Just think about it that all the function as input and output object is defined in the header file.

Line no# 3:

Another thing that always appears in the C++ program, is int main(). So, This is called a function. All the program’s code will write in function with curly brackets {} and the program will execute.

Line no# 5:

C++ ignores the blank line with with spaces.

Line no# 6:

cout (pronounced as see-out) is an object used together with the insertion operator (<<) to display/output/print the text on the screen. So, In our example, it will give the output “Hello World!”.

Note: Every C++ statement will be end with Semicolon ( ; ) and we could write as the body of function int main(); and int main(); { cout << “Hello TCMaster world!” return 0; }

Remember: Compiler Ignores white spaces and, comments, make your code more efficient and readable by using single line and multi-line comments.

Line no# 7:

return 0; So, this code make the program complete.

Note: Don’t miss putting close curly bracket } at the end of the program. but, if you miss this then compile gives you an error.


Use of Namespace:

So, You might be seen in some C++ programs they do not use the namespace standard library. So, They omitted and replace the Line using namespace std; with std; keyword, And following this:: operator for some objects :

Example:

#include <include>

int main(){
    std::cout << "Hello World!";
    return 0;
}

Output:

Hello World!

So, here is our Recent Topic

  1. Introduction to C++ Programming then follows the number two.
  2. C++ Syntax – Learn C++ Programming and then follows the number Three.
  3. Comment in C++ – Single-line & Multi-line and then follows the number Four.
  4. C++ Output (Display Text) – C++ New Lines and then follows the number Fiver.
  5. C++ Variables and Learn C++ Programming and Learn C++ Complete.

So, Readers! be enjoy your learning, and if you have any inquiry about course, please comment below.

By Usama Arshad

It's me Usama Arshad working as a Lecturer C++. I am a student of BSIT.

Leave a Reply

Your email address will not be published. Required fields are marked *