Can I retrieve a one-dimensional array address from a two-dimensional array?

I am new to programming. This code does not work properly, that is, to retrieve the address of a one-dimensional array from a two-dimensional array:

#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]) ;
}

In order to be more precise, instead of using C functions, pass the array through the pointer to the function (printf() here), and you can use the pointer to the array here Pointers:

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]) ;
}

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.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2747 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.