The Main Function

C does not spefify any return type for the main() function which is the starting point for the execution of a program. The definition of main() would look like this:

main()
{
// main program statements
}
This is perfectly valid because the main in C does return any value.
In C++, the main return a value of type int to be operating system. C++, therefore explicitly defines main() as matching one of the following prototypes:
int main()
int main(int argc, char *argv[]);

The function that have a return value should use the return statement for termination. The main() function in C++ is, therefore, define as fallows:
int main()
{
.......
.......
return 0;
}

No comments:

Post a Comment