• Register
100 points
7 2
Welcome to Kodlogs, programming questions and answer website.

A simple C++ program contains header files, blank or white spaces, main function, output statement, operators and return statement. But we can create a program without using some of them. So, our question is what should every C++ program contain?

What should every C++ program contain?

Every C++ program must have a function known as main i.e., int main()
Program execution always begins with the main function. 

Why is the main function so important?

int main() is a part of every C++ program. It tells the compiler that program execution begins at the next line. Exactly one one function in every program must be named main. C++ programs begin executing at function main, even if main is not the first function defined in the program. The keyword int to the left of main indicates that main “returns” an integer(whole number) value. 

Code

#include<iostream>
using namespace std;
int main()
{
    cout << "Hello world!!!";
    return 0;
}

Here int main() indicates that the execution of the program begins from the next line.

#include<iostream>
using namespace std;

{
    cout << "Hello world!!!";
    return 0;
}

 If we ignore int main() for some weird reason then the compiler will show error as error: expected unqualified-id before '{' token
 {
 ^

 

Hope it will help.

100 points
7 2