Saturday, February 11, 2017

*p++ understanding

*p++ understanding

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. 3.1 — Operator precedence and associativity
  2. C Operator Precedence Table
  3. Operators in C and C++
  4. Does *p++ increment after dereferencing? [duplicate]
  5. ++ on a dereferenced pointer in C?
  6. How does “while(*s++ = *t++)” copy a string?
  7. C++ Operator Precedence
  8. C Operator Precedence
  9. Do you know what *p++ does in C?
  10. Subject: Re: *p++
  11. The pre- and postfix versions of incr/decr have different precedence levels.
  12. Operators, with Precedence and Associativity
  13. Precedence and Order of Evaluation
  14. C/Precedence
  15. CS223
  16. KernighanRitchie
  17. C Operator Precedence

No comments:

Post a Comment