Main function (programming) |
In some programming languages, the main function is where a program starts execution.
It is the first user-written function (programming) run when a program starts (some system-specific software generally runs before the main function). The main function usually organizes at a high level the functionality of the rest of the program. The main function typically has access to the program s command-line arguments.
= C and C++ =
In C programming language and C plus plus, the function prototype of the main function is:
int main(int argc, char **argv)
The parameter (computer science)s argc and argv respectively give the number and value of the program s command-line arguments. Some systems permit a third parameter envp , which gives access to the program s software platform.
The name main is special; normally every C and C++ program must define precisely one function of that name.
= Java =
Java programming language programs start executing at the main method (computer science), which has the following method heading:
public static void main(String[] args)
Command-line arguments are passed in args . As in C and C++, the name main is special. Java s main methods don t return anything.
= Pascal =
In Pascal programming language, the main procedure is the only unnamed procedure in the program. Because Pascal programs have the procedures and functions in a more rigorous top-down order than C, C++ or Java programs, the main procedure is usually the last procedure in the program. Pascal does not have a special meaning for the name main or any similar name.
Example: procedure hello() begin writeln( Hello world ) end; begin hello() end.
= Python =
In Python programming language a function called main doesn t have any special significance. However, it is common practice to organize a program s main functionality in a function called main and call it with code similar to the following:
def main(): if __name__ == __main__ : main()
When a Python program is executed directly (as opposed to being imported from another program), the special global variable __name__ has the value __main__ .
= External link =
|
|
