Breaking

Sunday, April 29, 2018

Structure of C++ program



For making the c++ program you need to know how to write the code means what is the syntax, what is the structure.

1 . Header

2 . using namespace std;

3 . main function

{
  Code here
  return 0;
}

Now we make program that will give the output hello world :

#include<iostream>
using name std;
int main()
{
    cout<<”Hello World”;
    return 0;
}

Finish, when you compile this program the output will be Hello World.
Now we talk about every step in detail.

1.  Header :

C++ defines several header, which contain information that is either necessary or useful to your program. For this program, the header <iostream> is needed.
C++ input/output stream are primarily defined by <iostream>

2.  The line using namespace std; :

Tells the compiler to use the std namespace. Namespaces are a relatively recent addition to C++.
std is the standard namespacecout, cin and a lot of other things are defined in it. This means that one way to call them is by using std::cout and std::cin.

3.  The line int main() :

Is the main function where program execution begins.

4.  The next line cout << "Hello World"; :

Causes the message "Hello World" to be displayed on the screen.
cout is use for to display something on the screen.
Syntax of cout is cout<<”message”;

5.  The next line return 0; :

Terminates main( ) function and causes it to return the value 0 to the calling process. In other words we can say that the execution of program will be stop.
In C++, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.


No comments:

Post a Comment