Main (Entry Point)
- C
- C++
- C#
- Java
- Rust
- Go
- Javascript
- Typescript
- Python
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:
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:
public class MyClassName
{
public static void Main(string[] args)
{
// Code Here
}
}
More Info:
public static void main(String[] args)
{
// Code Here
}
fn main() {
// Code Here
}
// Args Example
fn main() {
let args: Vec<String> = std::env::args().collect();
for arg in args {
println!("{}", arg);
}
}
package main
import "fmt"
func main() {
// Code Here
fmt.Println("Hello World")
}
// Args Example
package main
import (
"fmt"
"os"
)
func main() {
for _, arg := range os.Args {
fmt.Println(arg)
}
}
// 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();
// Args Example (Node)
const args = process.argv.slice(2);
for (const arg of args) {
console.log(arg);
}
// 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();
// Args Example (Node)
const args: string[] = process.argv.slice(2);
for (const arg of args) {
console.log(arg);
}
# 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()
# Args Example
import sys
for arg in sys.argv[1:]:
print(arg)