Use this tag for questions about entry points to executables (programs); e.g., the "main()" function in most programming languages. If your question is programming language specific, tag that: language as well e.g. C, C++, Java etc.
Questions tagged [program-entry-point]
2997 questions
8066
votes
46 answers
What does if __name__ == "__main__": do?
What does this do, and why should one include the if statement?
if __name__ == "__main__":
print("Hello, World!")
If you are trying to close a question where someone should be using this idiom and isn't, consider closing as a duplicate of Why…

Devoted
- 177,705
- 43
- 90
- 110
1859
votes
63 answers
What does "Could not find or load main class" mean?
A common problem that new Java developers experience is that their programs fail to run with the error message: Could not find or load main class ...
What does this mean, what causes it, and how should you fix it?

Stephen C
- 698,415
- 94
- 811
- 1,216
1364
votes
46 answers
Can't execute jar- file: "no main manifest attribute"
I have installed an application and when I try to run it (it's an executable jar) nothing happens. When I run it from the command line with:
java -jar "app.jar"
I get the following message:
no main manifest attribute, in "app.jar"
Normally, if I…

Ewoud
- 13,845
- 5
- 18
- 23
830
votes
19 answers
What should main() return in C and C++?
What is the correct (most efficient) way to define the main() function in C and C++ — int main() or void main() — and why? And how about the arguments?
If int main() then return 1 or return 0?
There are numerous duplicates of this question,…

Joel
- 15,166
- 16
- 39
- 31
539
votes
37 answers
Why is the Java main method static?
The method signature of a Java mainmethod is:
public static void main(String[] args) {
...
}
Is there a reason why this method must be static?

Alotor
- 7,407
- 12
- 38
- 36
388
votes
18 answers
What is the "String args[]" parameter in the main method?
What does the following Java code mean?
public static void main(String[] args)
What is String[] args?
When would you use these args?
Source code and/or examples are preferred over abstract explanations.

freddiefujiwara
- 57,041
- 28
- 76
- 106
290
votes
12 answers
Is main a valid Java identifier?
One of my kids is taking Java in high school and had this on one of his tests:
Which of the following is a valid identifier in Java?
a. 123java
b. main
c. java1234
d. {abce
e. )whoot
He answered b and got it wrong.
I looked at the question…

Gary Bak
- 4,746
- 4
- 22
- 39
168
votes
9 answers
Should I return EXIT_SUCCESS or 0 from main()?
It's a simple question, but I keep seeing conflicting answers: should the main routine of a C++ program return 0 or EXIT_SUCCESS?
#include
int main(){return EXIT_SUCCESS;}
or
int main(){return 0;}
Are they the exact same thing? Should…

Trevor Hickey
- 36,288
- 32
- 162
- 271
164
votes
5 answers
What is the proper declaration of main in C++?
Questions
What is the proper signature of the main function in C++?
What is the correct return type, and what does it mean to return a value from main?
What are the allowed parameter types, and what are their meanings?
Is this…

fredoverflow
- 256,549
- 94
- 388
- 662
146
votes
8 answers
No Main() in WPF?
I am a beginner when it comes to programming but I was sure that one of the universal rules was that a program starts with Main(). I do not see one when I create a WPF project. Is Main() simply named something differently in WPF?

Juice
- 2,860
- 4
- 22
- 20
137
votes
4 answers
"int main (vooid)"? How does that work?
I recently had to type in a small C test program and, in the process, I made a spelling mistake in the main function by accidentally using vooid instead of void.
And yet it still worked.
Reducing it down to its smallest complete version, I ended up…

paxdiablo
- 854,327
- 234
- 1,573
- 1,953
136
votes
12 answers
Is main() really start of a C++ program?
The section $3.6.1/1 from the C++ Standard reads,
A program shall contain a global
function called main, which is the
designated start of the program.
Now consider this code,
int square(int i) { return i*i; }
int user_main()
{
for ( int i = 0…

Nawaz
- 353,942
- 115
- 666
- 851
130
votes
7 answers
In Python, can I call the main() of an imported module?
In Python I have a module myModule.py where I define a few functions and a main(), which takes a few command line arguments.
I usually call this main() from a bash script. Now, I would like to put everything into a small package, so I thought that…

Ricky Robinson
- 21,798
- 42
- 129
- 185
122
votes
5 answers
Why do we need argc while there is always a null at the end of argv?
It seems that the argv[argc] is always NULL, so I think we can traverse the argument list without argc. A single while loop will do this.
If there is always a NULL at the end of argv, why do we need an argc?

StarPinkER
- 14,081
- 7
- 55
- 81
116
votes
3 answers
Why main does not return 0 here?
I was just reading
ISO/IEC 9899:201x Committee Draft — April 12, 2011
in which i found under 5.1.2.2.3 Program termination
..reaching the } that terminates the main function returns a value of 0.
it means if you don't specify any return…

Jeegar Patel
- 26,264
- 51
- 149
- 222