How do you Assign an address to an element of pointer array?
Pointers were always difficult subject to understand. I would
suggest to read several tutorials and spend some time playing with
them.
Explanation:
/* create array of two pointers to integer */
int *aaa[2];
/* setting first pointer in array to point to 0x1212 location in
memory */
aaa[0] = (int *)0x1212;
/* allocate memory for the second pointer and set value */
aaa[1] = malloc(sizeof(int));
*aaa[1] = 333;
/* if you want to can make first item to point to the
second,
now arr[0] pointer address changed to the same as aaa[1] pointer
*/
aaa[0] = aaa[1];
/* print aaa[1] address and later print value */
printf("LOCATION: %X\n", (unsigned int)*(aaa + 1));
printf("VALUE: %d\n", **(aaa + 1));
/* exact the same here, but different way of how I wrote
pointers */
printf("LOCATION: %X\n", (unsigned int)aaa[1]);
printf("VALUE: %d\n", *aaa[1]);
If you would do the same with 0 element of array, which points
to 0x1212 memory location you would get some kind of number or Bus
error if you accessed restricted memory place (for example the
beginning of memory).
I hope this I did not make you more confused than you are.