#include
main() {
int s[4][2] = {
{1234, 56 },
{1212 , 33 },
{1434, 80 },
{1312, 78 }
};
int i ;
for (i = 0; i <= 3 ; i++ )
printf (" Address of %d th 1-D array = %u", i, s[i]) ;
}
for (i = 0; i <4; i++) {
int (*ptr)[2] = &(s[ i]);
printf (" Address of %d th 1-D array = %p ", i, (void*)ptr) ;
}
The difference between s [i] and &(s [i]) is that s [i] is a 1d array and the type is int [2], where &(s [i]) is a pointer to int [ 2], what you want.
For example, you can use the sizeof operator to view it: sizeof(s [i]) here is 2 * sizeof(int), where sizeof(&(s [i])) Has the size of a pointer variable.
I am a newbie in programming. This code does not work properly, that is, to retrieve the address of a one-dimensional array from a two-dimensional array: < p>
#include
main() {
int s[4][2] = {
{1234 , 56 },
{1212, 33 },
{1434, 80 },
{1312, 78 }
};
int i ;
for (i = 0; i <= 3; i++ )
printf (" Address of %d th 1-D array = %u", i, s[i]) ;
} pre>In order to be more precise, instead of using C functions, pass the array through the pointer to the function (here, printf()), and you can use the pointer to the array here. :
for (i = 0; i <4; i++) {
int (*ptr)[2] = &(s[i] );
printf (" Address of %d th 1-D array = %p ", i, (void*)ptr) ;
}s [i] and &(s [i]) is that s [i] is a 1d array and the type is int [2], where &(s [i]) is a pointer to int [2] , What you want.
For example, you can use the sizeof operator to view it: sizeof(s [i]) here is 2 * sizeof(int), where sizeof(&(s [i ])) has the size of a pointer variable.