Difference between (*++argv)[0] and while(c = *++argv[0])

后端 未结 5 2041
后悔当初
后悔当初 2020-12-09 18:33

I have the following snippet of code:

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

     char line[MAXLINE];
     long lineno = 0;
     int c, except = 0, number =          


        
5条回答
  •  死守一世寂寞
    2020-12-09 19:22

    The parentheses change the order in which the expressions are evaluated.

    Without parentheses *++argv[0]:

    1. argv[0] gets the pointer to character data currently pointed to by argv.
    2. ++ increments that pointer to the next character in the character array.
    3. * gets the character.

    with parentheses (*++argv)[0]:

    1. ++argv increments the argv pointer to point to the next argument.
    2. * defereferences it to obtain a pointer to the character data.
    3. [0] gets the first character in the character array.

提交回复
热议问题