I'm learning C++ with the Qt framework and noticed that `QApplication` is commonly created with `int argc` and `char *argv[]`. What do these parameters represent, and why does Qt need them?
4 Answers
The declaration looks complicated because `char *argv[]` is an array of pointers to characters—in practical terms, an array of null-terminated strings. You can loop from `0` to `argc - 1` and print `argv[i]` to see each argument.
For example, if you run `myprogram hello 123`, the values are approximately `argc = 3`, `argv[0] = "myprogram"`, `argv[1] = "hello"`, and `argv[2] = "123"`. The program name is normally included as the first argument, and `argv[argc]` is a null pointer marking the end of the array.
Qt accepts these values so `QApplication` can inspect and handle command-line options intended for Qt. A typical program looks like `int main(int argc, char *argv[]) { QApplication app(argc, argv); ... }`. If your `main` currently has no parameters, you can add them and pass them to `QApplication`.
They contain the command-line arguments used to start the program. `argc` is the number of arguments, while `argv` is an array of C-style strings containing the arguments.

That makes sense. I’m using C++ and hadn’t added those parameters to my `main` function yet.