D
DiAvOl
Hello everyone, merry christmas!
I have some questions about the following program:
arrtest.c
------------
#include <stdio.h>
int main(int agc, char *argv[]) {
int array2d[2][2] = { {1,2} , {3,4} };
int (* arrp)[2] = array2d;
printf("&array2d = %p\tarray2d = %p\t*array2d = %p\n", &array2d,
array2d, *array2d);
printf("&arrp = %p\tarp = %p\t*arrp = %p\t**arp = %d\n", &arrp,
arrp, *arrp, **arrp);
return 0;
}
When I compile and run the program I get the following results:
&array2d = 0xbfd9e880 array2d = 0xbfd9e880 *array2d = 0xbfd9e880
&arrp = 0xbfd9e890 arrp = 0xbfd9e880 *arrp =
0xbfd9e880 **arrp = 1
My questions are:
Why is the address of array2d (&array2d), the value (array2d) and the
contents of that value (*array2d) all the same ? (0xbfd9e880)
array2d contains the value: 0xbfd9e880. When dereferenced (*array2d)
it gives the same value, 0xbfd9e880
But when the same address is dereferenced again (**array2d) it gives
an integer (1) and not an address like above.
How does the compiler "understands" if it should return a pointer or
the value stored in that address?
How does the compiler stores array variables so that &array == array ?
Thanks for your time, I hope you will understand my questions
I have some questions about the following program:
arrtest.c
------------
#include <stdio.h>
int main(int agc, char *argv[]) {
int array2d[2][2] = { {1,2} , {3,4} };
int (* arrp)[2] = array2d;
printf("&array2d = %p\tarray2d = %p\t*array2d = %p\n", &array2d,
array2d, *array2d);
printf("&arrp = %p\tarp = %p\t*arrp = %p\t**arp = %d\n", &arrp,
arrp, *arrp, **arrp);
return 0;
}
When I compile and run the program I get the following results:
&array2d = 0xbfd9e880 array2d = 0xbfd9e880 *array2d = 0xbfd9e880
&arrp = 0xbfd9e890 arrp = 0xbfd9e880 *arrp =
0xbfd9e880 **arrp = 1
My questions are:
Why is the address of array2d (&array2d), the value (array2d) and the
contents of that value (*array2d) all the same ? (0xbfd9e880)
array2d contains the value: 0xbfd9e880. When dereferenced (*array2d)
it gives the same value, 0xbfd9e880
But when the same address is dereferenced again (**array2d) it gives
an integer (1) and not an address like above.
How does the compiler "understands" if it should return a pointer or
the value stored in that address?
How does the compiler stores array variables so that &array == array ?
Thanks for your time, I hope you will understand my questions