I wish to refer to the following code related to my question.
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("%c\n", argv[1][1]);
return 0;
}
usually prior to creating a pointer, there must exist the variable in the first place. But in C command line arguments, *argv[] is not refered to an already defined char argv but it is actually a two dimensional array that contains not only addresses but also elements of command line arguments. How can this happen. I would appreciate the theory behind this.
My second question is how could a pointer array come to contain the elements of the command line arguments?
main()? Magic! As to "how could a pointer array come to contain the elements of the command line arguments" – since the command line arguments are strings, and in C, strings are usually referred to by a pointer to their first character.