我可以从二维数组中检索一维数组地址吗?

abh*_*ari 4 c arrays data-structures

我是编程新手.此代码无法正常工作,即从二维数组中检索一维数组地址:

#include<stdio.h>

main() {
     int s[4][2] = {
                    { 1234, 56 },
                    { 1212, 33 },
                    { 1434, 80 },
                    { 1312, 78 }
                   };
     int i ;
     for ( i = 0 ; i <= 3 ; i++ )
         printf ( "\nAddress of %d th 1-D array = %u", i, s[i] ) ;
}
Run Code Online (Sandbox Code Playgroud)

LPs*_*LPs 6

#include<stdio.h>

int main( )
{
    int s[4][2] = {
                    { 1234, 56 },
                    { 1212, 33 },
                    { 1434, 80 },
                    { 1312, 78 }
                } ;

    int i ;
    for ( i = 0 ; i < 4 ; i++ )
        printf ( "\nAddress of %d th 1-D array = %p\n", i, (void *)s[i] ) ;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

正如您在发布的代码中看到的那样,使用%p格式来打印地址.此格式说明符需要void *传递参数.