I wanted to make sure that I understand the concept of the pointer to an array of n elements, for example: int (*myarr)[10]; //myarr is a pointer to an array that can hold 10 integer
I've tried the following code:
void main(){ int arr[][3] = { { 10, 20, 50 }, { 30, 60, 90 }, { 22, 92, 63 } }; int(*arrptr)[3]; /* a pointer to an array of 3 ints*/ int *ip = arr[0]; arrptr = arr; int index; for (index = 0; index < 9; index++) { printf("[ %d ][ %p ]\n\n", *ip, ip);ip++; } for (index = 0; index < 3; index++) { printf("%x <-> %p,%d\n", *arrptr, arrptr,**arrptr); arrptr++; } } and I got that
*[ 10 ][ 001BFA40 ]* [ 20 ][ 001BFA44 ] [ 50 ][ 001BFA48 ] *[ 30 ][ 001BFA4C ]* [ 60 ][ 001BFA50 ] [ 90 ][ 001BFA54 ] *[ 22 ][ 001BFA58 ]* [ 92 ][ 001BFA5C ] [ 63 ][ 001BFA60 ] *1bfa40* <-> *001BFA40*,10 1bfa4c <-> 001BFA4C,30 1bfa58 <-> 001BFA58,22
As I understand, the arrptr holds the whole address which the array is pointing to. This would mean that the pointer can move freely in these ranges of addresses.
But, why is the address value that holds arrptr equal to the address that holds the value of arr[0]?
In other words: I know it's normal that *arrptr holds the address of arr[0], but the address of arrptr that contains the place where the arrptr will point to is the same where arr[0] ?!
arrptr", as you never use&arrptr. Please be more precise in your wording, to avoid misunderstandings.%pis used to print avoid-pointer's value. That's all.