# I still do not understand offset, please give me examples

• 11-13-2002
I still do not understand offset, please give me examples
Okay, I am not jumping the gun on this one, I have been trying to figure out exactly what an offset is. I read it like every other page and I try to figure out what it means but it doesn't ever make sense.

Can someone give me some examples of an offset? try to explain them as specific as possible

thanks.
• 11-13-2002
Prelude
Consider an array declared as

int a[5];

In memory it looks like a very poor attempt at ascii art (really, it does!)
Code:

```|------|  |------|  |------|  |------|  |------| | a[0] |  | a[1] |  | a[2] |  | a[3] |  | a[4] | |------|  |------|  |------|  |------|  |------|```
The first element, a[0] can be considered the base memory address for the array. To access further elements, you use an offset from that base address:

int *p = a + 2;

This pointer now points to a[2] because you took the base address and added the offset of 2 to it, moving the pointer down in memory two spaces the size of an int. This is basically all an offset is, a certain amount of space past a base memory address.

-Prelude
• 11-13-2002