If I let p be a pointer attached to the first element of an integer array. Could someone explain the difference between the C operators (*p)++ and *(p++)?
cheers
If I let p be a pointer attached to the first element of an integer array. Could someone explain the difference between the C operators (*p)++ and *(p++)?
cheers
What is the difference between *p and p++?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I'm assuming your question is a doubt concerning the other thread you posted.
Basically, when doing:
The pointer 'p' is pointing to the array's first element's address. When doing:Code:int *p = arr;
You are not referring to the pointer's address, rather to its value, which is insignificant to us at this point. Because, you are dereferencing the pointer. The other way (*(p++)), you are actually referencing the array's address and summing one to it, which would lead the array to return the next element in the array.Code:(*p)++
(*p)++
Add one to the value at p.
*(p++)
Give the value at p, then add one unit to the address of p, a unit being the size of the datatype.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge