I have this program:
#include <stdio.h>
int main(int argc, char *argv[]) {
int i;
for (i=0; i < argc;i++) {
printf("argv[%d] = %s\n", i, argv[i]);
}
}
I am wondering about the argument char *argv[]. My first thought was that this was an array of character pointers? But then it should compile if we write: (char *argv)[]? But then I get the error meassage
testargs.c:3:20: error: expected declaration specifiers or '...' before '(' token
3 | int main(int argc, (char *argv)[]) {
However it will compile and run correctly if I have char *(argv[]). But what is this actually in terms of pointers and arrays? Is it a character pointer to an array, or what is it?
This represents an array of pointers to
char, in other words, strings. The way you recognize this is that the array syntax[]is demoted to a pointer, so this is the same as**char, a pointer to pointers ofchars.