Operator precedence in c with pointers

后端 未结 5 1778
面向向阳花
面向向阳花 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:22

    It is easy to remember which has precedence when you consider prefix increment.

    what has precedence here?

    *++array = x; // pretty obvious

    the same precedence rules go for the postfix expression so its rather easy.

    The same goes for the cast operator.

    (somestruct *)x + 1;

    first the cast is done since if it wasn't the following wouldnt make sense

    x + (int)1;

提交回复
热议问题