/* * Unlike Java, main() is not a method. Therefore, no class declaration. * * There are only two valid declarations for main: * int main() * int main(int argc, char *argv[]) * * Don’t even ask about void main(). It does not exist. ⚠ ☢ ☣ ☠ * * main returns an int, a success/failure code to the invoker. * 0: success, >0: failures of varying sorts * Negative values are just weird. Many environments (e.g., bash) will * only use the lower eight bits of the return value. E.g., -1 ⇒ 255, * which will be confused with a signal return value, 128+signum. * * argc: number of arguments, including the program name as argv[0] * “argc” stands for “argument count” * argv: array of C-style strings, corresponding to program arguments * “argv” stands for “argument vector” * * argc is always ≥ 1, except in strange embedded environments. * The type of argv is always an array of C strings, even if you type * arguments that look like numbers or something else. * * Why is argv[] an array of char *? Surely it should be strings? * - C++ strings didn’t exist in C. * * Why is argv[] an array of char *? Surely it should be const char *? * - C didn’t have const when this was all invented. * - It’s your memory, you should be able to change it. */ #include using namespace std; int main(int argc, char *argv[]) { // Display all arguments, including program name. for (int i=0; i