• Home
  • Structure of C++ Program with Example

Structure of C++ Program with Example

Here is an example of the structure of a C++ program:

#include <iostream>

using namespace std;

int main()
cout << "Hello, World!" << endl;

return 0;

In this example, the program includes the iostream header file, which provides access to the cout and endl functions. The using namespace std directive allows the program to use the cout and endl functions without specifying their namespace.

The main function is the entry point of the program. It is where the program execution begins and ends. In this example, the main function uses the cout function to print the string “Hello, World!” to the standard output, followed by a newline character using the endl function.

Finally, the return 0 statement indicates that the program has finished executing successfully.

Overall, this is a simple example of a C++ program that demonstrates the basic structure of a C++ program. It includes a header file, a namespace directive, a main function, and a return statement.