Operator precedence in c with pointers

后端 未结 5 1768
面向向阳花
面向向阳花 2020-12-30 19:13

How to analyse the precedence in following situation .

for (i=0; i<20; i++)
{
    *array_p++ = i*i;
    printf(\"%d\\n\",*arr++);
}

how

5条回答
  •  北海茫月
    2020-12-30 19:28

    Postfix operators have higher precedence than unary operators, so *x++ is parsed as *(x++); the result of the expression x++ (which is x) is dereferenced.

    In the case of *++x, both * and ++ are unary operators and thus have the same precedence, so the operators are applied left-to-right, or *(++x); the result of the expression ++x (which is x + sizeof *x) is dereferenced.

提交回复
热议问题