"Krish Jasani" <23*1*3*
8@s*u*e*t*u*a*e*u*a*> wrote:
> I had a doubt in calculating the new value of 'p', when the operation of ++p or --p is performed. So this operation signifies that another consecutive element of the array is accessed. But what if the other element occupies the space greater than or less than 4 bytes?? Is that even possible or not??
I can't quite understand the 2nd part of your question.
If p is a pointer of type T, the incrementing or decrementing of p will increase or decrease its value by sizeof(T).
The sizeof(T) is not always 4 - it literally depends on the amount of memory required to store one instance of T, and it may be 1, 2, 4, 8 .... (or other values if T is not a base-type but a user-defined structure).
p doesn't 'know', and can't check' that it is actually pointing at memory holding a T.
If p is decremented to an address that is 'before' the beginning of an array, there are no guarantees that the memory before the array is storing a T, and so p may point to a location that is not of type T.
Hope this helps,