配列を指すダブルポインタから2D配列の行と列の数を取得しようとしています。
#include <stdio.h>
#include <stdlib.h>
void get_details(int **a)
{
int row = ??? // how get no. of rows
int column = ??? // how get no. of columns
printf("\n\n%d - %d", row,column);
}
上記の関数は、問題が発生しているサイズの詳細を出力する必要があります。
int main(int argc, char *argv[])
{
int n = atoi(argv[1]),i,j;
int **a =(int **)malloc(n*sizeof(int *)); // using a double pointer
for(i=0;i<n;i++)
a[i] = (int *)malloc(n*sizeof(int));
printf("\nEnter %d Elements",n*n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
printf("\nEnter Element %dx%d : ",i,j);
scanf("%d",&a[i][j]);
}
get_details(a);
return 0;
}
配列を作成するためにmallocを使用しています。
このようなものを使用するとどうなりますか
column = sizeof(a)/ sizeof(int)?