user-0 提问: 新人求助，子函数如何返回二维数组

回复:
user: user-1
content: 简单的看看C语言书上关于指针和函数返回值部分的内容吧，不然记不住的。

user: user-2
content: 仅供参考：#include <stdio.h> #include <stdlib.h> #include <malloc.h> int **newarr2d(int rows,int cols) {     int **p,i;      p=(int **)malloc(rows*sizeof(int *));     if (NULL==p) exit(1);     for (i=0;i<rows;i++) {         p[i]=(int *)malloc(cols*sizeof(int));         if (NULL==p[i]) exit(1);     }     return p; } void deletearr2d(int **p,int rows) {     int i;      for (i=0;i<rows;i++) {         free(p[i]);     }     free(p); } int main() {     int **arr2d,i,j,r,c;      r=4;     c=5;     //在堆中开辟一个4×5的二维int数组     arr2d=newarr2d(r,c);     for (i=0;i<r;i++) {         for (j=0;j<c;j++) {             arr2d[i][j]=i*c+j;         }     }     for (i=0;i<r;i++) {         for (j=0;j<c;j++) {             printf(" %2d",arr2d[i][j]);         }         printf("\n");     }     deletearr2d(arr2d,r);      r=6;     c=3;     //在堆中开辟一个6×3的二维int数组     arr2d=newarr2d(r,c);     for (i=0;i<r;i++) {         for (j=0;j<c;j++) {             arr2d[i][j]=i*c+j;         }     }     for (i=0;i<r;i++) {         for (j=0;j<c;j++) {             printf(" %2d",arr2d[i][j]);         }         printf("\n");     }     deletearr2d(arr2d,r);      return 0; } //  0  1  2  3  4 //  5  6  7  8  9 // 10 11 12 13 14 // 15 16 17 18 19 //  0  1  2 //  3  4  5 //  6  7  8 //  9 10 11 // 12 13 14 // 15 16 17 //

user: user-0
content: double function(double b1, double c1, double d1, double a2, double b2, double c2, double d2, double xi, double eta) { 	int m, n; 	int i, j; 	double pi = 3.1415926; 	double y = 0.25*(a2 + b2*xi + c2*eta + d2*xi*eta); 	double jacobi[3][3] = { 0 }; 	double partial_xi[5] = { 0 }; 	double partial_eta[5] = { 0 }; 	double partial_x[5] = { 0 }; 	double partial_y[5] = {0}; 	double deter; 	double phi[5] = { 0, 0.25*(1 - xi)*(1 - eta), 0.25*(1 + xi)*(1 - eta), 0.25*(1 + xi)*(1 + eta), 0.25*(1 - xi)*(1 + eta) }; 	double fun[5][5]; 	jacobi[1][1] = 0.25*(b1 + d1*eta); 	jacobi[1][2] = 0.25*(b2 + d2*eta); 	jacobi[2][1] = 0.25*(c1 + d1*xi); 	jacobi[2][2] = 0.25*(c2 + d2*xi); 	deter = jacobi[1][1] * jacobi[2][2] - jacobi[1][2] * jacobi[2][1];  	partial_xi[1] = -1.0 / 4 * (1 - eta); 	partial_xi[2] = 1.0 / 4 * (1 - eta); 	partial_xi[3] = 1.0/ 4 * (1 + eta); 	partial_xi[4] = -1.0 / 4 * (1 + eta); 	partial_eta[1] = -1.0 / 4 * (1 - xi); 	partial_eta[2] = -1.0 / 4 * (1 + xi); 	partial_eta[3] = 1.0 / 4 * (1 + xi); 	partial_eta[4] = 1.0 / 4 * (1 - xi); 	partial_x[1] = 1.0 / deter*(jacobi[2][2] * partial_xi[1] - jacobi[1][2] * partial_eta[1]); 	partial_x[2] = 1.0 / deter*(jacobi[2][2] * partial_xi[2] - jacobi[1][2] * partial_eta[2]); 	partial_x[3] = 1.0 / deter*(jacobi[2][2] * partial_xi[3] - jacobi[1][2] * partial_eta[3]); 	partial_x[4] = 1.0 / deter*(jacobi[2][2] * partial_xi[4] - jacobi[1][2] * partial_eta[4]); 	partial_y[1] = 1.0 / deter*(jacobi[1][1] * partial_eta[1] - jacobi[2][1] * partial_xi[1]); 	partial_y[2] = 1.0 / deter*(jacobi[1][1] * partial_eta[2] - jacobi[2][1] * partial_xi[2]); 	partial_y[3] = 1.0 / deter*(jacobi[1][1] * partial_eta[3] - jacobi[2][1] * partial_xi[3]); 	partial_y[4] = 1.0 / deter*(jacobi[1][1] * partial_eta[4] - jacobi[2][1] * partial_xi[4]); 	for (m = 1; m <= 4; m++) 	for (n = 1; n <= 4; n++) 	{ 		fun[m][n] = 2 * pi*((partial_x[m] * partial_x[n] + partial_y[m] * partial_y[n])*y + 2 * phi[m] * partial_y[n])*deter; 		a[m][n] = fun[m][n]; 		//printf("%f\n", fun[m][n]); 		return(a[m][n]); 	}  	return(a[1][1]); }

user: user-0
content: 非常感谢赵4老师，问题解决了