What is the difference between the following pointer expressions
*ptr++
++*ptr
(*ptr)++
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first one will is equivalent to
*(ptr++)which will will return a temporary pointer with it’s current value and then increment ptr.The second one will increment the value pointed to by
ptr(assuming it is a type with++defined) and return the incremented valueThe third one will return the current value pointed to by
ptrand then incrementptrEx.
a = 0, b = 0, but
ptrwill point to nonsense.a = 1, b = 1
a = 1, b = 0