News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

What are the basics of main()?

Started by VelMurugan, Dec 17, 2008, 04:41 AM

Previous topic - Next topic

VelMurugan

What are the basics of main()?

function main() is the application's main routine where a program starts execution.It is the first user-written function run when a program starts.Object-oriented C++ programs consist mostly of classes, but there's always at least one C-like function: main(). main() is called more or less at the beginning of the program's execution, and when main() ends, the runtime system shuts down the program. main() always returns an int, as shown below:

int main() {
// ...Your Code goes here...
}


main() has a special feature: There's an implicit return 0; at the end. Thus if the flow of control simply falls off the end of main(), the value 0 is implicitly returned to the operating system. Most operating systems interpret a return value of 0 to mean "program completed successfully."

main() is the only function that has an implicit return 0; at the end. All other routines that return an int must have an explicit return statement that returns the appropriate int value.

Note that this example shows main() without any parameters. However, main() can optionally declare parameters so that it can access the command line arguments, just as in C.

Source : IndiaTimes