Why is *p++ different from *p += 1?

后端 未结 4 1212
天涯浪人
天涯浪人 2020-12-04 15:25

Consider:

void foo1(char **p) { *p++; }
void foo2(char **p) { *p += 1; }

and

char *s = \"abcd\";
char *a = s; 
foo1(&a)         


        
4条回答
  •  旧时难觅i
    2020-12-04 15:57

    Precedence of prefix ++ and * is same. Associativity of both is right to left. Precedence of postfix ++ is higher than both * and prefix ++. Associativity of postfix ++ is left to right.

提交回复
热议问题