M
mdh
I guess pointers just take time!!!
This is exercise 5-13, peripherally.
The function accepts a command line argument of -n.
So, given
int main ( int argc, char *argv[])
.......
if ( argc == 2 && (*++argv)[0]=='-')
n= atoi(argv[0]+1);
......
May I ask this?
1) in a given function ( ? scope ?) once one has advanced the pointer
( to argv..in this case) is that where the pointer will remain
pointing at? and until when?
2) In the case above, where Tondo and Gimpel use indices as well as
pointer incrementation, is there a good reason for this or is this
just a matter of style? ie why not use ( instead of (*++argv)[0])
argv[1][0]? ( if that indeed is equivalent?)
3) I have until now not seen the construct "atoi(argv[0]+1". Does this
mean get the pointer at index argv[1] ( which I believe is an pointer
to char array, then add 1 to that pointer? ( not argv)?
Thanks in advance.
This is exercise 5-13, peripherally.
The function accepts a command line argument of -n.
So, given
int main ( int argc, char *argv[])
.......
if ( argc == 2 && (*++argv)[0]=='-')
n= atoi(argv[0]+1);
......
May I ask this?
1) in a given function ( ? scope ?) once one has advanced the pointer
( to argv..in this case) is that where the pointer will remain
pointing at? and until when?
2) In the case above, where Tondo and Gimpel use indices as well as
pointer incrementation, is there a good reason for this or is this
just a matter of style? ie why not use ( instead of (*++argv)[0])
argv[1][0]? ( if that indeed is equivalent?)
3) I have until now not seen the construct "atoi(argv[0]+1". Does this
mean get the pointer at index argv[1] ( which I believe is an pointer
to char array, then add 1 to that pointer? ( not argv)?
Thanks in advance.