Re: pointing to a memory position

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Quoted text here. Click to load it

That's OK, just go ahead.

In C, an array name is a constant pointer to the array base address, and an
indexing operation is equivalent to using a pointer constructed as the sum
of the base pointer and index value.

If there is:

 char arr[20],

arr is a constant char* pointing to the base of the array.

 arr[i] is equivalent to *(arr + i)

A word of caution:

The indexing in C takes the size of the array base type into account, so the
byte index into an int array may produce a surprise. In indexing, the
machine byte address is increased by the amount of sizeof(base type)*index.

So, to access a Flash chip residing at 0x01000000:

 unsigned char *ptr = (unsigned char *)0x01000000;

  ptr[256]  is the byte at address 0x01000100.


Tauno Voipio
tauno voipio @ iki fi

Site Timeline