Question

the following does not compile:

int main (int argc, char *argv[]) {
    char arr[2][2];
    char **ptr = arr;
    return 0;
}

Yet the following does:

int main (int argc, char *argv[]) {
    char **ptr = argv;
    return 0;
}

Thus I would conclude that argv is not a c style array which is stored as a single block of memory but rather is some sort of pointer array. Can somebody confirm that?

Thank you and Regards.

Was it helpful?

Solution

That's correct, argv is a pointer to the first element of an array of pointers, each of which in turn (except for the last one) is a pointer to the first character in a string of characters giving the respective command line argument.

Function parameters cannot be arrays.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top