Operator precedence in c with pointers

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

    Operators ++ and * have the same precedence (postfix or prefix).However the associativity in such cases is from right to left. so in cases like

    *ptr++ ==>  *(ptr++) 
    *++ptr ==> *(++ptr)
    ++*ptr ==> ++(*ptr)
    

    this link should give you more information on operators precedence and their associativity.. http://www.isthe.com/chongo/tech/comp/c/c-precedence.html

提交回复
热议问题