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
70
votes
6 answers
Is main() overloaded in C++?
2 valid versions of main() exist in C++:
int main() // version 1
int main(int argc, char **argv) // version 2
But both overloads cannot coexist at the same time. Why not? (Potential use case: while running the program from the terminal, if no…

iammilind
- 68,093
- 33
- 169
- 336
70
votes
18 answers
Run single kotlin class with main function in android studio
I am trying to get familiar with Kotlin to use in my android apps. So first I want to try out some simple kotlin examples, just to get familiar with syntax of kotlin.
I made a class named Main.kt in my android project with just main method.
fun…

Vikalp
- 2,051
- 4
- 18
- 24
67
votes
8 answers
C++ - char** argv vs. char* argv[]
What is the difference between char** argv and char* argv[]? in int main(int argc, char** argv) and int main(int argc, char* argv[])?
Are they the same? Especially that the first part does not have [].

Simplicity
- 47,404
- 98
- 256
- 385
66
votes
7 answers
Does int main() need a declaration on C++?
I was taught that functions need declarations to be called. To illustrate, the following example would give me an error as there is no declaration for the function sum:
#include
int main() {
std::cout << "The result is " << sum(1, 2);
…

vinibrsl
- 6,563
- 4
- 31
- 44
65
votes
10 answers
"Error: Main method not found in class MyClass, please define the main method as..."
New Java programmers often encounter messages like the following when they attempt to run a Java program. (Different Java tools, IDEs and so on give a variety of diagnostics for this problem.)
Error: Main method not found in class MyClass, please…

Stephen C
- 698,415
- 94
- 811
- 1,216
65
votes
3 answers
How does this C program compile and run with two main functions?
Today, while working with one custom library, I found a strange behavior.
A static library code contained a debug main() function. It wasn't inside a #define flag. So it is present in library also. And it is used link to another program which…

MrPavanayi
- 887
- 8
- 17
64
votes
10 answers
Difference between int main() and int main(void)?
What does the following mean :
int main(void) {...}
VS
int main() {...}
?
I think that int main() {...} means that main doesn't receive any parameters (from command line) , however:
int main(int argc, char *argv[])
does.
But, what does int…

JAN
- 21,236
- 66
- 181
- 318
62
votes
8 answers
Difference between void main and int main in C/C++?
Does it matter which way I declare the main function in a C++ (or C) program?

Kredns
- 36,461
- 52
- 152
- 203
62
votes
10 answers
Where are C/C++ main function's parameters?
In C/C++, the main function receives parameters which are of type char*.
int main(int argc, char* argv[]){
return 0;
}
argv is an array of char*, and points to strings. Where are these string located? Are they on the heap, stack, or somewhere…

remainn
- 1,125
- 3
- 9
- 14
62
votes
6 answers
Why does declaring main as an array compile?
I saw a snippet of code on CodeGolf that's intended as a compiler bomb, where main is declared as a huge array. I tried the following (non-bomb) version:
int main[1] = { 0 };
It seems to compile fine under Clang and with only a warning under…

Theodoros Chatzigiannakis
- 28,773
- 8
- 68
- 104
62
votes
6 answers
Why does Rust not have a return value in the main function, and how to return a value anyway?
In Rust the main function is defined like this:
fn main() {
}
This function does not allow for a return value though. Why would a language not allow for a return value and is there a way to return something anyway? Would I be able to safely use…

Jeroen
- 15,257
- 12
- 59
- 102
61
votes
6 answers
How to test the main package functions
I want to test a few functions that are included in my main package, but my tests don't appear to be able to access those functions.
My sample main.go file looks like:
package main
import (
"log"
)
func main() {
log.Printf(foo())
}
func…

ThePiachu
- 8,695
- 17
- 65
- 94
55
votes
2 answers
Access main package from other package
I want to access the main package from another package, but this is impossible because the main file isn't in a directory. I already tried putting the main file in a directory, but when I try to import it I get this error:
import "../main" is a…

Jan Wytze
- 3,307
- 5
- 31
- 51
55
votes
8 answers
Explanation of 'String args[]' and static in 'public static void main(String[] args)'
How can you explain very well, to a beginner, the meaning of String args[] and the use of static in the following excerpt?
class FirstApp {
public static void main(String[] args) {
...
}
}

Sam
- 3,067
- 19
- 53
- 55
54
votes
2 answers
Why SDL defines main macro?
After having some trouble setting up SDL, I found out that SDL defines a macro that replaces main:
#define main SDL_main
// And then
extern C_LINKAGE int SDL_main(int argc, char *argv[]);
This can also create compilation errors, if the main…

Tibi
- 4,015
- 8
- 40
- 64