Objective-c main routine, what is: int argc, const char * argv[]

后端 未结 6 1357
长情又很酷
长情又很酷 2021-02-05 07:40

What are the arguments passed into the main method of a command-line program:

int main(int argc, const char * argv[])

what is the first int mea

6条回答
  •  梦谈多话
    2021-02-05 08:20

    argc means "argument count". It signifies how many arguments are being passed into the executable. argv means "argument values". It is a pointer to an array of characters. Or to think about it in another way, it is an array of C strings (since C strings are just arrays of characters).

    So if you have a program "foo" and execute it like this:

    foo -bar baz -theAnswer 42
    

    Then in your main() function, argc will be 5, and argv will be:

    argv[0] = "/full/path/to/foo";
    argv[1] = "-bar";
    argv[2] = "baz";
    argv[3] = "-theAnswer";
    argv[4] = "42";
    

提交回复
热议问题