a pointer about *argv[] a pointer about *argv[] c c

a pointer about *argv[]


You need to add a pair of parentheses around (*argv) to change the order of evaluation. The way you currently have it, the [1] is evaluated first, yielding an invalid pointer, which then gets dereferenced, causing undefined behavior.

printf("%s\n", (*argv)[1]);


Argv is already a pointer. Just pass it like this:

init_arg(&argc, argv);

And init_arg should look like this:

void init_arg(int *argc, char **argv) {    printf("%s\n", argv[1]);}


I'm assuming that the reason for passing &argc and &argv in the first place is so that you can update them inside init_arg. Here's how I prefer to write such functions, in general:

/* * init_arg: do something useful with argc and argv, and update argc and argv * before returning so that the caller can do something else useful that's * not shared with all the other callers of init_arg(). * (this comment of course needs updating to describe the useful things) */void init_arg(int *argc0, char ***argv0) {    int argc = *argc0;    char **argv = *argv0;    ... all the operative code goes here, and then ...    *argc0 = argc;    *argv0 = argv;}

Of course this means you must not do early returns inside init_arg, so there are some tradeoffs, but it sure is a lot easier to work with the same regular old argc and argv inside init_arg.