Main_function_(programming) Main_function_(programming)

Main function (programming) - Definition and Overview

In some programming languages, the main function is where a program starts execution.

It is the first user-written function 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.

Contents

C and C++

In C and C++, the function prototype of the main function is:

int main(int argc, char **argv)

The parameters argc and argv respectively give the number and value of the program's command-line arguments. Some systems add a third parameter envp, which gives access to the program's environment.

The name "main" is special; every C and C++ program must have one function called main.

Java

Java programs start executing at the main method, 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.

Python

In Python 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():
    <main program>

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

Example Usage of (programming)

techgle_coding: Programming-Web Programming: I need to edit a flash object for my essay. http://forum.techgle.com/showthread.php?t=35565
matthiggs: Sass from "CTV Publicty" I called them on their lack of Cdn Programming and they mentioned Corner Gas,Degrassi &Flashpoint in their defense.
gajastar: @geborenimwinter TH kills them all! Run in fear, English speaking programming!
Copyright 2009 WordIQ.com - Privacy Policy  :: Terms of Use  :: Contact Us  :: About Us
This article is licensed under the GNU Free Documentation License. It uses material from the this Wikipedia article.