EmbLogic's Blog

what is difference between argc and argv
how to use it

One Response to

  1. msiddarth says:

    Actually argc and argv are command line parameters. argc means number of commands entered via command line and the entered command is stored as a string in argv which is a character of pointers.
    lets take an example
    when we want to execute a program we type the command as
    root@localhost~]#./a.out
    This command is treated as 1 by argc and the ./a.out is stored in argv[0].
    To get the result you can write a simple program as
    int main(int argc,char *argv[])
    {
    printf(” Command number: %d\n”,argc);
    printf(” Command name: %s\n”,argv[0]);
    return 0;
    }
    Subsequently the number of commands entered are stored in argv for example
    root@localhost~]#./a.out hello world
    argv[0] – ./a.out
    argv[1] – hello
    argv[2] – world
    and number of commands are three

Leave a Reply to msiddarth Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>