On Wed, Nov 18, 2009 at 8:48 PM, Rahul Gupta <
rah...@gmail.com> wrote:
>
> 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.
>
>
>
> 2009/11/18 tarang gupta <
tara...@gmail.com>
>>
>> sir the programme given for command line arguments on the lecture
>> notes at saroj mam's webpage for file handling given on the last slide
>> is not understandable
>> pls mail an explanation for it
>
>