Difference between ++*p, *p++ and *++p

The pre and post increment with *, I am confused here. Is it pointer in the first two cases?

  • Aditi
  • 06 मार्च
  • 1 उत्तर

1 उत्तर
1-1 of  1
1 Answer
  • The expression ++*p has two operators of same precedence, so compiler looks for assoiativity. Associativity of operators is right to left. Therefore the expression is treated as ++(*p). Therefore the output of first program is “arr[0] = 11, arr[1] = 20, *p = 11“.

    The expression *p++ is treated as *(p++) as the precedence of postfix ++ is higher than *. Therefore the output of second program is “arr[0] = 10, arr[1] = 20, *p = 20“.

    The expression *++p has two operators of same precedence, so compiler looks for assoiativity. Associativity of operators is right to left. Therefore the expression is treated as *(++p). Therefore the output of second program is “arr[0] = 10, arr[1] = 20, *p = 20“.
    -1

C Programming
मॉक परीक्षण अभ्यास के लिए
C Programming