The code given is
"
main(int argc,char *argv[])
{
while(argc>0) /* print out all arguments in reverse order*/
{
printf("%s\n",argv[argc-1]);
argc--;
}
}
"
1) argc stores the number of elements which would be there in the array argv
2) So just considering argv as an array with number of elements (= argc), how will you print the elements of that array in reverse order ??
Array argv has elements from i=0 till i=argc-1
You would start from the end of the array ie.from argv[argc-1] ..print the value stored at that location and decrement i.
The above program can be rewritten as
for (i=argc-1;i>0;i--)
printf("%s",argv[i];
Compare both the programs and understand how both of them are essentially the same only.