Core Features
Main function
An entry point where the execution starts.
Every single application must have a main function, which serves as the entrypoint to the program. It is the starting point where a program execute instructions to perform any tasks. Also, there must exist only one main function at a time, no more that two in the same source program.
Simple
main() functionint main(){
# code ...
return 0;
}
main() function for a command-line app that takes argumentsint main(string args[]){
# code ...
return 0;
}
A
main()function must exactly meet the following rules:
- The
main()function must be namedmain, defining an alias for it is not permitted.- The
main()function is a top-level function, so it must not be invoked by itself or by another function.- There must exist only two versions of the main function, either
main()ormain(string args[]).- The return type of the main function must be
intand an integer value must be returned from the function.- Trying to interact with
main()function by any actions, such as creating a pointer points to it, etc, will result in a compilation error.
The return value can be zero or non-zero integer!
- zero indicates a success.
- non-zero indicates a failure.