Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the name main for function main()

Tags:

java

c

main

Why the function name main() is retained in many languages like C, C++, Java? Why not any other names for that function? Is there any common structure for all these 3 main() (in C, C++, Java)

like image 797
Nethra Avatar asked Nov 06 '09 15:11

Nethra


People also ask

What does Main () mean in Python?

In Python, the special name __main__ is used for two important constructs: the name of the top-level environment of the program, which can be checked using the __name__ == '__main__' expression; and. the __main__.py file in Python packages.

What is meaning of if __ name __ == '__ Main__?

if __name__ == “main”: is used to execute some code only if the file was run directly, and not imported.

Is if name == Main necessary?

The Reason Behind if __name__ == '__main__' in Python You might have seen this one before: the syntax which often gets ignored because it doesn't seem to hinder the execution of your code. It may not seem necessary, but that's only if you're working with a single Python file.

Is there a main function in Python?

Some programming languages have a special function called main() which is the execution point for a program file. Python interpreter, however, runs each line serially from the top of the file and has no explicit main() function.


1 Answers

There are a lot of silly and not very respectful answers here to a legitimate question.

C didn't come from nowhere. Its immediate ancestor is B, written by Ken Thompson. Here is a link to the B manual. The basic structure of a B program is

main(); exit();

main() is provided by the programmer and exit() is supplied by the library. This seems to be the first appearance of main() as the predecessor of B, BCPL, has no such concept. I guess you would have to ask Ken Thompson why it was main and not something else.

like image 125
Tim Allman Avatar answered Sep 22 '22 04:09

Tim Allman