Search code examples
command-lineargumentscommand-line-argumentsargvargc

int argc, const char * argv[] , why we give these input to main


Why we give these arguments to main ,searched a lot but couldn't find an answer to clear this doubt.

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

Solution

  • argc represents the number of arguments passed to the main function.

    argv[] represents the arguments passed which are separated by space.

    Eg:-

    $ ./a.out First Second Third

    Program Name Is: ./a.out [argv[0]]

    Number Of Arguments Passed: 4 [argc value]

    ----Following Are The Command Line Arguments Passed----

    argv[0]: ./a.out

    argv[1]: First

    argv[2]: Second

    argv[3]: Third

    Refer here for more information