Skip to main content

Main (Entry Point)

C

int main(int argc, const char **argv)
{
// Code Here

return 0; // 0 (zero) means successful end of program
}
int main(int argc, const char *argv[])
{
// Code Here

return 0;
}
#include <stdlib.h> // For exit(), EXIT_SUCCESS, EXIT_FAILURE

int main(void)
{
// Code Here

// In some codes, instead of "return 0", you might find One of the following:
return exit(0);
return EXIT_SUCCESS;
return exit(EXIT_SUCCESS);
}

More Info:

C++ (Cpp)

int main(int argc, const char **argv)
{
// Code Here

return 0; // 0 (zero) means successful end of program
}
int main(int argc, const char *argv[])
{
// Code Here

return 0;
}
#include <cstdlib> // For exit(), EXIT_SUCCESS, EXIT_FAILURE

int main(void)
{
// Code Here

// In some codes, instead of "return 0", you might find One of the following:
return exit(0);
return EXIT_SUCCESS;
return exit(EXIT_SUCCESS);
}

More Info:

C# (Csharp)

public class MyClassName
{
public static void Main(string[] args)
{
// Code Here
}
}

More Info:

Java

public static void main(String[] args)
{
// Code Here
}

Rust

// Todo

Go

// Todo

Javascript

// You dont need a main function. The Code runs top to bottom
// But, if you want to be organized:

function main() {
// Code Here
}

main();
// Self Invoking Function
(function main() {
// Code Here
})();
class Main {
static Run() {
// Code Here
}
}

Main.Run();
// TODO Args Example (Node)

Typescript

// You dont need a main function. The Code runs top to bottom
// But, if you want to be organized:

function main(): void {
// Code Here
}

main();
class Main {
public static Run(): void {
// Code Here
}
}

Main.Run();
// TODO Args Example

Python

# You dont need a main function. The Code runs top to bottom
# But, if you want to be organized:

def main():
# Code Here

main()

# There are no "{ }", you need to use ":" and indentation
# You can have either spaces or tabs but not both mixed
def main():
# Code Here

# Conditional to check If you are running the source file as
# the main program entry point (Instead of importing it from another file)

if (__name__ == "__main__"):
main()
class Main:
@staticmethod
def run():
# Code Here

if (__name__ == "__main__"):
Main.run()
# TODO Args Example