C++ Program Structure

Understand C++ Program Parts

First C++ Program that display output "Welcome to first C++ Program!”.  With example below

//C++ Program First Program structure comment
1
#include <iostream> 
2
int main()  
3
4
std::cout << "Welcome to c++ Program !"; 
5
}
6




1- C++ Program Comment
 Program comments are helpful statements. These comments help anyone for reading the source code. It is simply a line written by the coder or programmer for his own understanding syntax or to make other understand his program syntax code. The compiler does not includes this line while compilation. 
For more detail click here.

2- Header #include<iostream>
It defined standard input/output stream Header files contain definitions of Functions and Variables, which is imported or used into any C++ program by using the pre-processor #include statement.

For example we are using iostream that is one of the most basic C++ libraries! It is used for input and output.

cin and cout is example of function for input and output stream. If you run program without including iostream then error will done because compiler ask no cout , cin library founded.

3- main function
int / void is a return value, which will be explained in a while. The main () is the main function where program execution begins. Every C++ program must contain only one main function.

4- {
Start of the function main

5- Print output code

cout is function for display output in C++. A statement must always terminate with a semicolon; 

6- }
End of the main function

Using namespace std


If you have noticed that C++ language, you may have seen cout being used instead of std::cout. Both name the same object: the first one uses its unqualified name (cout), while the second qualifies it directly within the namespace std(as std::cout).

cout is part of the standard library, and all the elements in the standard C++ library are declared within what is called a namespace:
Using namespace std.


//C++ Program First Program structure comment
#include <iostream> 
using namespace std;
int main()  
cout << "Welcome to first c++ Program !"; 
}


above program is without using namespace std and here example with using namespace feature.


<< C++ Installation     --           C++ Token >> 

No comments:

Post a Comment