- #1
Crystal037
- 167
- 7
- Homework Statement
- Returning 2d array from a function by passing pointer to that array.
- Relevant Equations
- None
C:
#include <stdio.h>
#include<stdlib.h>
int** make(int**x,int y,int z);
void read(int **x,int y,int z);
int main()
{
int ** r;
int a,b;
scanf("%d %d",&a,&b);
/*r=(int**)malloc(sizeof(int*)*a);
for(int i=0;i<b;i++){
r[i]=(int*)malloc(sizeof(int**));
}*/
make(r,a,b);
//r=make(r,a,b);
/*for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
scanf("%d",&r[i][j]);
for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
printf("%d",r[i][j]);*/
read(r,a,b);
}
int** make(int**x,int y,int z){
x=(int**)malloc(sizeof(int*)*y);
for(int i=0;i<z;i++){
x[i]=(int*)malloc(sizeof(int**));
}
return x;
}
void read(int **x,int y,int z){
for(int i=0;i<y;i++)
for(int j=0;j<z;j++)
scanf("%d",&x[i][j]);
for(int i=0;i<y;i++)
for(int j=0;j<z;j++)
printf("%d",x[i][j]);
}
Last edited by a moderator: