changing pointers' destination relative to current position

This is a discussion on changing pointers' destination relative to current position within the C++ Programming forums, part of the General Programming Boards category; When you change where a pointer points to in the following manner:
Code:
char *ptr;
ptr++;
ptr+=5;
ptr--;
ptr-=5;
Is ...

changing pointers' destination relative to current position

When you change where a pointer points to in the following manner:

Code:

char *ptr;
ptr++;
ptr+=5;
ptr--;
ptr-=5;

Is it relative to the base type? That means to say, in this case it would point one byte ahead, then six, then five, then at it's original spot. If it it was an [32-bit] int pointer, it would point four, twenty-four, twenty, then zero bytes ahead of the original value. Is this correct? I would think so. Or incrementing and decrementing pointer addresses always on the granularity of one byte? Thank you.

>Is this correct?
Yes, consider arrays. The data type of each element in the array determines how big each element is. If the array is of char, each element is the size of a char, if it is int then each element is the size of an int. Arrays are degraded into pointers like so:
a[i] == *( a + i )

If a is of char then *( a + i ) will move the pointer to i char past a, if a is of in then the same action is performed except the pointer will move i int past a. The same thing goes for pointers that were dynamically allocated.

Hey much thanks there friend. I probably should have tested it myself. And your new information is great in that we can use user defined structures on it too, I wonder if that's how classes would behave... [In DJGPP tho, just for the sake of mentioning, you'd have to use the PACKED attribute so that it's, well PACKED and not aligned on 32-bit bounds per piece of data in the structure] Also I would figure that the data in a class array would be contigious since I've heard [and would figure so] that the classes member function code is only created once, and that only the data is replicated at runtime, and if it's a pointer I'd hope it was adjacent and orderly, other than the PACKED issue.