I’ve read the first array member of argv will always be the program name.
Is it ever useful to hang on to this? I’m learning, so forgive me please if it is a dumb question.
Do people ever unshift the first member because it is useless (and reset argv to be one less?), or is leaving it there best practice because people expect it will always be there (and for it to work out of the box with argc) ?
It should be. C and C++ both require that if
argcis greater than zero,argv[0]shall either be the program name or an empty string.Some systems do not necessarily follow this convention in all circumstances (on Windows, for example, you can use
CreateProcessto create a new process and not pass the program name in the command line arguments that are used to populateargcandargv).Sure. If you want to spawn another instance of yourself, for example, or if you want to print your program name (for example in usage instructions).
Don’t change the actual arguments; the next person who comes along will probably be expecting them to be in their original form.