Question: My application has potentially a huge number of arguments passed in and I want to avoid the memory of hit duplicating the arguments into a filtered list. I would like to filter them in place but I am pretty sure that messing with argv array itself, or any of the data it points to, is probably not advisable. Any suggestions?

Answer: 
The latest draft of the C standard (N1256) states that there are two allowed forms of the `main` function:

```
int main (void);
int main (int argc, char* argv[]);

```

but the crux is the clause "or in some other implementation-defined manner". This seems to me to be a loophole in the standard large enough to drive a semi-trailer through.

Some people specifically use `"const char *"` for the `argv` to disallow changes to the arguments. If your main function is defined that way, you are not permitted to change the characters that `argv[]` points to, as evidenced by the following program:

```
pax> cat qq.c
#include <stdio.h>
int main (int c, const char *v[]) {
    *v[1] = 'X';
    printf ("[%s]\n", v[1]);
    return 0;
}

pax> gcc -o qq qq.c
qq.c: In function `main':
qq.c:3: error: assignment of read-only location

```

However, if you remove the `"const"`, it works fine:

```
pax> cat qq2.c
#include <stdio.h>
int main (int c, char *v[]) {
    *v[1] = 'X';
    printf ("[%s]\n", v[1]);
    return 0;
}

pax> gcc -o qq2 qq2.c ; ./qq2
[Xello]

```

I think this is also the case for C++. The current draft states:

```
All implementations shall allow both of the following definitions of main:
    int main();
    int main(int argc, char* argv[]);

```

but it doesn't specifically disallow other variants so you could presumably accept a `"const"` version in C++ as well (and, in fact, g++ does).

The only thing you need to be careful of is trying to increase the size of any of the elements. The standards do *not* mandate how they're stored so extending one argument may (probably will) affect others, or some other unrelated data.
The only time I would say that directly manipulating argv is a *bad* idea would be when an application changes its behavior depending on the contents of argv[0].

However, changing a program's behavior depending on argv[0] is in itself a very *bad* idea where portability is a concern.

Other than that, you can treat it just like you would any other array. As Jonathan said, GNU getopt() permutes the argument list non-destructively, I've seen other getopt() implementations that go as far as serializing and even hashing the arguments (useful when a program comes close to ARG\_MAX).

Just be careful with your pointer arithmetic.