Polyglot CheatSheet - Main

Updated: 2021-11-19

C++

int main(int argc, char** argv) {
  // ...
  return 0;
}
  • argc: argument count
  • argv: argument vector

Java

Java code must live in a class.

class Foo {
  public static void main(String args[]) {
    // ...
  }
}

Python

if __name__ == "__main__":
  # running directly
else:
  # imported

Rust

use std::env

fn main(){
  for argument in env::args() {
    println!("{}", argument);
  }
}