top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between expressions *ptr++ and ++*ptr in C?

+4 votes
906 views
What is the difference between expressions *ptr++ and ++*ptr in C?
posted Mar 29, 2016 by Mohammed Hussain

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+3 votes

*ptr++ and ++*ptr both * and ++ have same precedence but due to associativity of operators from right to left both can be written as
*(ptr++) and ++(*ptr) so
*ptr++ => *(ptr++) => First it wil change its pointing value(address) that is,ptr will point to next value(address) just after old value and then derefence to get value.
++*ptr => ++(*ptr) => it will increment the value pointed by ptr.

answer Mar 29, 2016 by Shivam Kumar Pandey
...